finally get ares-sc2 bot running on macos with M3 / arm64 chip
so many kengs
first i have uninstall rye, and install pyenv, install poetry // poetry keep complaining python version errors.
uninstall rye: https://mac.install.guide/python/install-rye. // scroll to the end
pyenv and poetry: https://dev.to/mattcale/pyenv-poetry-bffs-20k6
remember add path "export PATH="$HOME/.local/bin:$PATH""
pyenv install 3.11 // the ares-sc2 bot specified version to be >=3.11 and <3.12.
when running poetry install
got error: "Installing cython-extensions-sc2 (0.4.4): Failed Error -3 while decompressing data: invalid distance too far back"
the error is because the package is built on linux not mac
to fix this,
go ares-sc2/pyproject.toml, comment out cython-extensions-sc2 = "^0.4.0", and add cython-extensions-sc2 = { git = "https://github.com/AresSC2/cython-extensions-sc2.git"}
then poetry lock –no-update and poetry install –sync
now if we run "poetry run python run.py"
got another error: "ModuleNotFoundError: No module named ‘pkg_resources’"
to fix it, poetry add setuptools
run again
ImportError: dlopen(/Users/ferryzhou/.pyenv/versions/3.11.10/lib/python3.11/lib-dynload/_lzma.cpython-311-darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/xz/lib/liblzma.5.dylib
brew install xz
run again
ImportError: dlopen(/Users/ferryzhou/Projects/sc2_bots_ares/ares-sc2/sc2_helper/sc2_helper.cpython-311-darwin.so, 0x0002): tried: ‘/Users/ferryzhou/Projects/sc2_bots_ares/ares-sc2/sc2_helper/sc2_helper.cpython-311-darwin.so’ (mach-o file, but is an incompatible architecture (have ‘x86_64’, need ‘arm64e’ or ‘arm64’))
ok. my macbook pro 2023 is on M3, which use arm64
git clone https://github.com/danielvschoor/sc2-helper.git
install cargo
curl –proto ‘=https’ –tlsv1.2 -sSf https://sh.rustup.rs | sh |
add $HOME/.cargo/bin to path
cargo build
lots errors
warp suggested it’s because some env variables not set
added the following
export PYTHON_INCLUDE_DIR=$(python -c "from distutils import sysconfig; print(sysconfig.get_python_inc())")
export PYTHON_LIB_DIR=$(python -c "import sysconfig; print(sysconfig.get_config_var(‘LIBDIR’))")
same error, noticed "pyo3_ffi::boolobject::Py_True::hfb8b6c031c344b01 in libpyo3-4a88edf5219064d6.rlib18 ld: symbol(s) not found for architecture arm64"
searched google with "pyo3 cargo build arm64"
found solution https://github.com/PyO3/rust-numpy/issues/223
create ~/.cargo/config.toml
[target.aarch64-apple-darwin] rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
cargo build –manifest-path /Users/ferryzhou/Projects/sc2-helper/Cargo.toml –verbose
now succeed
cargo build –manifest-path /Users/ferryzhou/Projects/sc2-helper/Cargo.toml –release
ls -l /Users/ferryzhou/Projects/sc2-helper/target/release
we can see libsc2_helper.dylib
now swap the lib file
mv ares-sc2/sc2_helper/sc2_helper.cpython-311-darwin.so ares-sc2/sc2_helper/sc2_helper.cpython-311-darwin.so.x86_64
cp target/release/libsc2_helper.dylib ../sc2_bots_ares/ares-sc2/sc2_helper/sc2_helper.cpython-311-darwin.so
poetry run python run.py
raise IndexError(‘Cannot choose from an empty sequence’)
maps problem
open run.py, change path from windows to mac sc2 maps path
#MAPS_PATH: str = "C:\Program Files (x86)\StarCraft II\Maps" MAPS_PATH: str = "/Applications/StarCraft II/Maps"
run again, and now it succeeded!!!
poetry run python run.py Starting local game…