Farama-Foundation / MAgent2

An engine for high performance multi-agent environments with very large numbers of agents, along with a set of reference environments
https://magent2.farama.org
MIT License
199 stars 33 forks source link

Installation issues on Macos Python3.8 #19

Open merak0514 opened 1 year ago

merak0514 commented 1 year ago

When running

pip install magent2

I get the result

Looking in indexes: https://mirrors.cloud.tencent.com/pypi/simple
Collecting magent2
  Downloading https://mirrors.cloud.tencent.com/pypi/packages/ac/34/9e1951fbb296171aa67e544203ec3f88b1df0890e0ab848873b6c1c46852/magent2-0.3.2.tar.gz (4.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.1/4.1 MB 708.0 kB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [16 lines of output]
    Traceback (most recent call last):
      File "/Users/panhaoxuan/Desktop/project/29_magent/venv/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
        main()
      File "/Users/panhaoxuan/Desktop/project/29_magent/venv/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
      File "/Users/panhaoxuan/Desktop/project/29_magent/venv/lib/python3.8/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
        return hook(config_settings)
      File "/private/var/folders/xy/l65yxphj301_00q2fwk8gnk00000gn/T/pip-build-env-4y33qhv_/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
        return self._get_build_requires(config_settings, requirements=['wheel'])
      File "/private/var/folders/xy/l65yxphj301_00q2fwk8gnk00000gn/T/pip-build-env-4y33qhv_/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
        self.run_setup()
      File "/private/var/folders/xy/l65yxphj301_00q2fwk8gnk00000gn/T/pip-build-env-4y33qhv_/overlay/lib/python3.8/site-packages/setuptools/build_meta.py", line 338, in run_setup
        exec(code, locals())
      File "<string>", line 116, in <module>
      File "<string>", line 21, in get_version
    FileNotFoundError: [Errno 2] No such file or directory: 'magent2/__init__.py'
    [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
QuiZet commented 1 year ago

I am getting the same issue on linux with pip install magent2 command pip version: 23.1.2 linux version: Ubuntu 20.04.4 LTS

Collecting magent2
  Using cached magent2-0.3.2.tar.gz (4.1 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [19 lines of output]
      Traceback (most recent call last):
        File "/home/yungisimon/anaconda3/envs/Farama_Hetero/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/yungisimon/anaconda3/envs/Farama_Hetero/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/yungisimon/anaconda3/envs/Farama_Hetero/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-ycn_xn10/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-ycn_xn10/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-ycn_xn10/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 116, in <module>
        File "<string>", line 21, in get_version
      FileNotFoundError: [Errno 2] No such file or directory: 'magent2/__init__.py'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
QuiZet commented 1 year ago

failed to compile from source, with python3 setup.py install as well.

elliottower commented 1 year ago

python3 setup.py install

Sorry for the delay on this issue, but I think this is now fixed. Editable mode (pip install -e .) still has some issues due to CMake which I'm not well versed enough to be able to fix, but running python3 setup.py install should work now. Installing locally via pip install . also works.

If you are interested in helping out further we would love to have extra hands helping with making proper testing to ensure things like this work (on other farama projects our CI installs on different python versions on linux and mac osx to ensure things work as intended). This project doesn't currently have any testing through pytest either, but that requires domain knowledge of the library, which I unfortunately do not have, and the other previous maintainers haven't had much time to get around to it.

ChenJiangxi commented 5 months ago

python3 setup.py install

Sorry for the delay on this issue, but I think this is now fixed. Editable mode (pip install -e .) still has some issues due to CMake which I'm not well versed enough to be able to fix, but running python3 setup.py install should work now. Installing locally via pip install . also works.

If you are interested in helping out further we would love to have extra hands helping with making proper testing to ensure things like this work (on other farama projects our CI installs on different python versions on linux and mac osx to ensure things work as intended). This project doesn't currently have any testing through pytest either, but that requires domain knowledge of the library, which I unfortunately do not have, and the other previous maintainers haven't had much time to get around to it.

I installed successfully using pip install ., but still got the following error message when executing from magent2.environments import battle_v4:

from magent2.environments import battle_v4 Traceback (most recent call last): File "", line 1, in File "/Users/xxx/CodeProject/MARL/MAgent2/magent2/init.py", line 1, in from magent2 import gridworld, utility File "/Users/xxx/CodeProject/MARL/MAgent2/magent2/gridworld.py", line 10, in from magent2.c_lib import _LIB, as_float_c_array, as_int32_c_array File "/Users/xxx/CodeProject/MARL/MAgent2/magent2/c_lib.py", line 43, in _LIB = _load_lib() File "/Users/xxx/CodeProject/MARL/MAgent2/magent2/c_lib.py", line 22, in _load_lib lib = ctypes.CDLL(path_to_so_file, ctypes.RTLD_GLOBAL) File "/Users/xxx/anaconda3/envs/marl/lib/python3.8/ctypes/init.py", line 373, in init self._handle = _dlopen(self._name, mode) OSError: dlopen(/Users/xxx/CodeProject/MARL/MAgent2/magent2/libmagent.dylib, 0x000A): tried: '/Users/xxx/CodeProject/MARL/MAgent2/magent2/libmagent.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/xxx/CodeProject/MARL/MAgent2/magent2/libmagent.dylib' (no such file), '/Users/xxx/CodeProject/MARL/MAgent2/magent2/libmagent.dylib' (no such file)

I wonder if there are any solutions to this? thx.

elliottower commented 5 months ago

Again I’m not a domain expert but it appears that the installation process involves copying the “libmagent” file in the build folder, explained here: https://github.com/Farama-Foundation/MAgent2/blob/d4ec94d243c1fe3fdeb3dc45a366637504127afa/setup.py#L15 and done for Linux here: https://github.com/Farama-Foundation/MAgent2/blob/d4ec94d243c1fe3fdeb3dc45a366637504127afa/.github/workflows/gh-pages.yml#L27

It seems that that libmagent file has a different extension (.so) on Linux and .dylib on MacOS, as seen here: https://github.com/Farama-Foundation/MAgent2/blob/d4ec94d243c1fe3fdeb3dc45a366637504127afa/magent2/c_lib.py#L15

TLDR look for that file it says is missing, and copy it to the place where it is looking for it.

I think this should be something that can be fixed in the setup.py or elsewhere, but maybe it’s a manual process. I will leave fixing this to someone better versed in c++ as I am quite unfamiliar. FWIW the way I found those links above was just searching this repo for the file in the error, if in doubt you can usually figure things like that out in the same way yourself if someone like me isn’t able to respond quickly