为什么我在尝试使用 pip 安装gym openai 时遇到错误?

问题描述 投票:0回答:4

我尝试使用 pip 命令安装gym,这是我得到的错误。我需要帮助。

它还给出了 Pillow 的错误。“为 Pillow 运行 setup.py install ... 错误” 我对使用 pip 进行安装非常陌生。非常感谢任何帮助。

我已经尝试升级 PIP 和 Pillow,但发现另一个错误: 错误:pip 的依赖项解析器当前未考虑所有已安装的软件包。此行为是以下依赖性冲突的根源。 健身房 0.18.0 需要枕头<=7.2.0, but you have pillow 8.1.0 which is incompatible.

(base) Meets-MacBook-Pro:~ meetpandya$ sudo pip install gym
WARNING: The directory '/Users/meetpandya/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting gym
  Downloading gym-0.18.0.tar.gz (1.6 MB)
     |████████████████████████████████| 1.6 MB 4.1 MB/s 
Requirement already satisfied: scipy in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from gym) (1.6.0)
Requirement already satisfied: numpy>=1.10.4 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/numpy-1.20.0rc2-py3.9-macosx-10.9-x86_64.egg (from gym) (1.20.0rc2)
Requirement already satisfied: pyglet<=1.5.0,>=1.4.0 in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from gym) (1.5.0)
Collecting Pillow<=7.2.0
  Downloading Pillow-7.2.0.tar.gz (39.1 MB)
     |████████████████████████████████| 39.1 MB 54.5 MB/s 
Collecting cloudpickle<1.7.0,>=1.2.0
  Downloading cloudpickle-1.6.0-py3-none-any.whl (23 kB)
Requirement already satisfied: future in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (from pyglet<=1.5.0,>=1.4.0->gym) (0.18.2)
Using legacy 'setup.py install' for gym, since package 'wheel' is not installed.
Using legacy 'setup.py install' for Pillow, since package 'wheel' is not installed.
Installing collected packages: Pillow, cloudpickle, gym
    Running setup.py install for Pillow ... error
    ERROR: Command errored out with exit status 1:
     command: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-04_zwf00/pillow_6f6eee9de0ba4d39860be5d1c9e6fb13/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-04_zwf00/pillow_6f6eee9de0ba4d39860be5d1c9e6fb13/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/tmp/pip-record-8mkbg8ib/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.9/include/python3.9/Pillow
         cwd: /private/tmp/pip-install-04_zwf00/pillow_6f6eee9de0ba4d39860be5d1c9e6fb13/
    
    The headers or library files could not be found for zlib,
    a required dependency when compiling Pillow from source.
    
    Please see the install instructions at:
       https://pillow.readthedocs.io/en/latest/installation.html
    
    Traceback (most recent call last):
      File "/private/tmp/pip-install-04_zwf00/pillow_6f6eee9de0ba4d39860be5d1c9e6fb13/setup.py", line 864, in <module>
        setup(
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/__init__.py", line 165, in setup
        return distutils.core.setup(**attrs)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/install.py", line 546, in run
        self.run_command('build')
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/build.py", line 135, in run
        self.run_command(cmd_name)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/build_ext.py", line 340, in run
        self.build_extensions()
      File "/private/tmp/pip-install-04_zwf00/pillow_6f6eee9de0ba4d39860be5d1c9e6fb13/setup.py", line 694, in build_extensions
        raise RequiredDependencyException(f)
    __main__.RequiredDependencyException: zlib
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/tmp/pip-install-04_zwf00/pillow_6f6eee9de0ba4d39860be5d1c9e6fb13/setup.py", line 918, in <module>
        raise RequiredDependencyException(msg)
    __main__.RequiredDependencyException:
    
    The headers or library files could not be found for zlib,
    a required dependency when compiling Pillow from source.
    
    Please see the install instructions at:
       https://pillow.readthedocs.io/en/latest/installation.html
    
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-04_zwf00/pillow_6f6eee9de0ba4d39860be5d1c9e6fb13/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-04_zwf00/pillow_6f6eee9de0ba4d39860be5d1c9e6fb13/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/tmp/pip-record-8mkbg8ib/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.9/include/python3.9/Pillow Check the logs for full command output.
python macos pip python-imaging-library openai-gym
4个回答
0
投票

假设您已经升级了pip,请移除pillow和gym,然后重新安装。如果你觉得很难,你可以用这个命令做得更简单:

$ pip install --upgrade --force-reinstall Pillow, gym

$ pip install -I Pillow, gym

此冲突是因为您的电脑上安装了旧的gym版本,因此需要强制重新安装才能升级。如果这不能解决问题,并且最新版本的gym需要旧版本的Pillow(正如我在您的问题中读到的那样),则使用以下命令安装相应的枕头版本:

$ pip install -I Pillow==7.2.0

0
投票

我在网上寻找答案并找到了适合我的解决方案。在这里,

zlib 是从源代码构建枕头的依赖项,即使您在站点包中缓存了枕头。 我所做的是,

brew install zlib
将 zlib 库添加到路径,“brew info zlib”提供有关如何将 zlib 库以及包配置文件添加到路径的说明。 对于 Mac

export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"
export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"

pip install gym
这对我有用。

Python -> 3.9 Virtualenvironment -> Virtualenv(我没有在 conda 上测试过)

我希望这对你有用。

链接:https://github.com/openai/gym/issues/2138


0
投票

首先尝试不使用 sudo。如果还是不行你可以用pycharm下载,或者使用包直接放到文件夹下


-2
投票

使用 conda 对我有用的另一个解决方案是:

pip uninstall pillow
pip install pillow
conda install -c conda-forge gym
© www.soinside.com 2019 - 2024. All rights reserved.