Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editable install and local install issues #24

Open
elliottower opened this issue Jun 30, 2023 · 1 comment
Open

Editable install and local install issues #24

elliottower opened this issue Jun 30, 2023 · 1 comment

Comments

@elliottower
Copy link
Member

Making an issue as I don't know how to fix this problem myself, seems something to do with the CMake files and C++ null pointer errors?

pip install -e .
Obtaining file:///Users/elliottower/Documents/GitHub/MAgent2
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Installing backend dependencies ... done
  Preparing editable metadata (pyproject.toml) ... done
Requirement already satisfied: numpy>=1.21.0 in /Users/elliottower/anaconda3/lib/python3.9/site-packages (from magent2==0.3.2) (1.23.5)
Requirement already satisfied: pygame>=2.1.0 in /Users/elliottower/anaconda3/lib/python3.9/site-packages (from magent2==0.3.2) (2.3.0)
Building wheels for collected packages: magent2
  Building editable for magent2 (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building editable for magent2 (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [176 lines of output]
      /private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py:66: _BetaConfiguration: Support for `[tool.setuptools]` in `pyproject.toml` is still *beta*.
        config = read_configuration(filepath, True, ignore_option_errors, dist)
      running editable_wheel
      creating /private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-wheel-kz8_msv0/.tmp-cxeq7wjg/magent2.egg-info
      writing /private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-wheel-kz8_msv0/.tmp-cxeq7wjg/magent2.egg-info/PKG-INFO
      writing dependency_links to /private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-wheel-kz8_msv0/.tmp-cxeq7wjg/magent2.egg-info/dependency_links.txt
      writing requirements to /private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-wheel-kz8_msv0/.tmp-cxeq7wjg/magent2.egg-info/requires.txt
      writing top-level names to /private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-wheel-kz8_msv0/.tmp-cxeq7wjg/magent2.egg-info/top_level.txt
      writing manifest file '/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-wheel-kz8_msv0/.tmp-cxeq7wjg/magent2.egg-info/SOURCES.txt'
      reading manifest file '/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-wheel-kz8_msv0/.tmp-cxeq7wjg/magent2.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      warning: no files found matching '*.dylib'
      warning: no files found matching '*.dll'
      warning: no files found matching '*.so'
      adding license file 'LICENSE'
      writing manifest file '/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-wheel-kz8_msv0/.tmp-cxeq7wjg/magent2.egg-info/SOURCES.txt'
      creating '/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-wheel-kz8_msv0/.tmp-cxeq7wjg/magent2-0.3.2.dist-info'
      creating /private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-wheel-kz8_msv0/.tmp-cxeq7wjg/magent2-0.3.2.dist-info/WHEEL
      running build_py
      running build_ext
      -- The C compiler identification is AppleClang 13.1.6.13160021
      -- The CXX compiler identification is AppleClang 13.1.6.13160021
      -- Detecting C compiler ABI info
      -- Detecting C compiler ABI info - done
      -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
      -- Detecting C compile features
      -- Detecting C compile features - done
      -- Detecting CXX compiler ABI info
      -- Detecting CXX compiler ABI info - done
      -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
      -- Detecting CXX compile features
      -- Detecting CXX compile features - done
      -- Configuring done (1.4s)
      -- Generating done (0.0s)
      -- Build files have been written to: /private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/tmpsqljm83r.build-temp
      /Users/elliottower/documents/github/magent2
      CMakeFiles
      CMakeLists.txt
      CODE_OF_CONDUCT.rst
      LICENSE
      MANIFEST.in
      MAgent2-text.png
      README.md
      build
      dist
      docs
      magent-graph-1.gif
      magent-graph-2.gif
      magent2
      magent2.egg-info
      pyproject.toml
      requirements.txt
      setup.py
      src
      [ 25%] Building CXX object CMakeFiles/magent.dir/src/gridworld/RenderGenerator.cc.o
      [ 25%] Building CXX object CMakeFiles/testlib.dir/src/gridworld/RenderGenerator.cc.o
      [ 30%] Building CXX object CMakeFiles/magent.dir/src/gridworld/test.cc.o
      [ 35%] Building CXX object CMakeFiles/testlib.dir/src/gridworld/Map.cc.o
      [ 40%] Building CXX object CMakeFiles/magent.dir/src/gridworld/AgentType.cc.o
      [ 40%] Building CXX object CMakeFiles/magent.dir/src/gridworld/GridWorld.cc.o
      [ 40%] Building CXX object CMakeFiles/magent.dir/src/gridworld/RewardEngine.cc.o
      [ 55%] Building CXX object CMakeFiles/magent.dir/src/gridworld/Map.cc.o
      [ 55%] Building CXX object CMakeFiles/testlib.dir/src/gridworld/AgentType.cc.o
      [ 60%] Building CXX object CMakeFiles/testlib.dir/src/gridworld/GridWorld.cc.o
      [ 60%] Building CXX object CMakeFiles/testlib.dir/src/gridworld/test.cc.o
      [ 60%] Building CXX object CMakeFiles/testlib.dir/src/gridworld/RewardEngine.cc.o
      [ 70%] Building CXX object CMakeFiles/testlib.dir/src/runtime_api.cc.o
      [ 70%] Building CXX object CMakeFiles/magent.dir/src/runtime_api.cc.o
      /Users/elliottower/Documents/GitHub/MAgent2/src/gridworld/Map.cc:180:9: warning: variable 'p_view_inner' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
              default:
              ^~~~~~~
      /Users/elliottower/Documents/GitHub/MAgent2/src/gridworld/Map.cc:184:24: note: uninitialized use occurs here
          int start_inner = *p_view_inner;
                             ^~~~~~~~~~~~
      /Users/elliottower/Documents/GitHub/MAgent2/src/gridworld/Map.cc:161:22: note: initialize the variable 'p_view_inner' to silence this warning
          int *p_view_inner, *p_view_outer;
                           ^
                            = nullptr
      /Users/elliottower/Documents/GitHub/MAgent2/src/gridworld/Map.cc:180:9: warning: variable 'p_view_inner' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
              default:
              ^~~~~~~
      /Users/elliottower/Documents/GitHub/MAgent2/src/gridworld/Map.cc:184:24: note: uninitialized use occurs here
          int start_inner = *p_view_inner;
                             ^~~~~~~~~~~~
      /Users/elliottower/Documents/GitHub/MAgent2/src/gridworld/Map.cc:161:22: note: initialize the variable 'p_view_inner' to silence this warning
          int *p_view_inner, *p_view_outer;
                           ^
                            = nullptr
      /Users/elliottower/Documents/GitHub/MAgent2/src/gridworld/RewardEngine.cc:366:9: warning: variable 'ret' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
              default:
              ^~~~~~~
      /Users/elliottower/Documents/GitHub/MAgent2/src/gridworld/RewardEngine.cc:370:12: note: uninitialized use occurs here
          return ret;
                 ^~~
      /Users/elliottower/Documents/GitHub/MAgent2/src/gridworld/RewardEngine.cc:217:13: note: initialize the variable 'ret' to silence this warning
          bool ret;
                  ^
                   = false
      /Users/elliottower/Documents/GitHub/MAgent2/src/gridworld/RewardEngine.cc:366:9: warning: variable 'ret' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
              default:
              ^~~~~~~
      /Users/elliottower/Documents/GitHub/MAgent2/src/gridworld/RewardEngine.cc:370:12: note: uninitialized use occurs here
          return ret;
                 ^~~
      /Users/elliottower/Documents/GitHub/MAgent2/src/gridworld/RewardEngine.cc:217:13: note: initialize the variable 'ret' to silence this warning
          bool ret;
                  ^
                   = false
      [ 75%] Building CXX object CMakeFiles/testlib.dir/src/temp_c_booster.cc.o
      [ 80%] Building CXX object CMakeFiles/magent.dir/src/temp_c_booster.cc.o
      [ 85%] Building CXX object CMakeFiles/magent.dir/src/utility/utility.cc.o
      [ 90%] Building CXX object CMakeFiles/testlib.dir/src/utility/utility.cc.o
      1 warning generated.
      1 warning generated.
      1 warning generated.
      1 warning generated.
      [ 95%] Linking CXX executable /var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/tmpq8nslohk.build-lib/magent2/testlib
      [100%] Linking CXX shared library /var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/tmpq8nslohk.build-lib/magent2/libmagent.dylib
      [100%] Built target testlib
      [100%] Built target magent
      Traceback (most recent call last):
        File "/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/command/editable_wheel.py", line 155, in run
          self._create_wheel_file(bdist_wheel)
        File "/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/command/editable_wheel.py", line 344, in _create_wheel_file
          files, mapping = self._run_build_commands(dist_name, unpacked, lib, tmp)
        File "/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/command/editable_wheel.py", line 267, in _run_build_commands
          self._run_build_subcommands()
        File "/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/command/editable_wheel.py", line 294, in _run_build_subcommands
          self.run_command(name)
        File "/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/dist.py", line 1234, in run_command
          super().run_command(command)
        File "/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 87, in run
          self.copy_extensions_to_source()
        File "/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 108, in copy_extensions_to_source
          self.copy_file(regular_file, inplace_file, level=self.verbose)
        File "/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 350, in copy_file
          return file_util.copy_file(
        File "/private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/_distutils/file_util.py", line 115, in copy_file
          raise DistutilsFileError(
      distutils.errors.DistutilsFileError: can't copy '/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/tmpq8nslohk.build-lib/magent2/libmagent.cpython-39-darwin.so': doesn't exist or not a regular file
      /private/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/pip-build-env-48u8s0x5/overlay/lib/python3.9/site-packages/setuptools/_distutils/dist.py:988: _DebuggingTips: Problem in editable installation.
      !!

              ********************************************************************************
              An error happened while installing `magent2` in editable mode.

              The following steps are recommended to help debug this problem:

              - Try to install the project normally, without using the editable mode.
                Does the error still persist?
                (If it does, try fixing the problem before attempting the editable mode).
              - If you are using binary extensions, make sure you have all OS-level
                dependencies installed (e.g. compilers, toolchains, binary libraries, ...).
              - Try the latest version of setuptools (maybe the error was already fixed).
              - If you (or your project dependencies) are using any setuptools extension
                or customization, make sure they support the editable mode.

              After following the steps above, if the problem still persists and
              you think this is related to how setuptools handles editable installations,
              please submit a reproducible example
              (see https://stackoverflow.com/help/minimal-reproducible-example) to:

                  https://github.com/pypa/setuptools/issues

              See https://setuptools.pypa.io/en/latest/userguide/development_mode.html for details.
              ********************************************************************************

      !!
        cmd_obj.run()
      magent2.libmagent
      /var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/tmpq8nslohk.build-lib/magent2
      error: can't copy '/var/folders/5y/hjb1rykx58xcbwg6r04m76tr0000gn/T/tmpq8nslohk.build-lib/magent2/libmagent.cpython-39-darwin.so': doesn't exist or not a regular file
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building editable for magent2
Failed to build magent2
ERROR: Could not build wheels for magent2, which is required to install pyproject.toml-based projects

This is with current master, which works for pip install . and can also build from source via python3 setup.py install (see #19). I tested out the commands in another issue and got some other errors which may or may not be related:

>>> from magent2.environments import battle_v4, adversarial_pursuit_v4, tiger_deer_v4
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/elliottower/Documents/GitHub/MAgent2/magent2/__init__.py", line 1, in <module>
    from magent2 import gridworld, utility
  File "/Users/elliottower/Documents/GitHub/MAgent2/magent2/gridworld.py", line 10, in <module>
    from magent2.c_lib import _LIB, as_float_c_array, as_int32_c_array
  File "/Users/elliottower/Documents/GitHub/MAgent2/magent2/c_lib.py", line 43, in <module>
    _LIB = _load_lib()
  File "/Users/elliottower/Documents/GitHub/MAgent2/magent2/c_lib.py", line 22, in _load_lib
    lib = ctypes.CDLL(path_to_so_file, ctypes.RTLD_GLOBAL)
  File "/Users/elliottower/anaconda3/lib/python3.9/ctypes/__init__.py", line 382, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Users/elliottower/Documents/GitHub/MAgent2/magent2/libmagent.dylib, 0x000A): tried: '/Users/elliottower/Documents/GitHub/MAgent2/magent2/libmagent.dylib' (no such file)

I ran cmake . as I saw it in the setup.py file, and that created a build directory which has the libmagent file. My guess is that I'm running the wrong command to install locally. Would be good to add to documentation how to build from source, how to build locally, etc (probably in a CONTRIBUTING.md file)

@elliottower elliottower changed the title Editable install fails Editable install and local install issues Jun 30, 2023
@BolunDai0216
Copy link

BolunDai0216 commented Dec 4, 2023

I assume you did

git clone https://github.com/Farama-Foundation/MAgent2.git
cd MAgent2
mkdir build && cd build
cmake ..
cmake --build .

The last line

OSError: dlopen(/Users/elliottower/Documents/GitHub/MAgent2/magent2/libmagent.dylib, 0x000A): tried: '/Users/elliottower/Documents/GitHub/MAsent2/magent2/libmagent.dylib' (no such file)

shows that libmagent.dylib cannot be located. You would need to add the path of where libmagent.dylib is to DYLD_LIBRARY_PATH. To do this, you can just add the following line to your ~/.zshrc file

export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/path/to/MAgent2/build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants