为什么在尝试使用 pip 安装gym openai 时出现错误?

问题描述

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

它也给了枕头错误。'运行 setup.py install for Pillow ...错误' 我对使用 pip 进行安装非常陌生。非常感谢任何帮助。

我已经尝试升级 PIP 和枕头,但发现另一个错误错误:pip 的依赖项解析器当前未考虑所有已安装的包。此行为是以下依赖项冲突的根源。 健身房 0.18.0 需要 Pillow

(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",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",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,'"'"'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.

解决方法

假设你已经升级了pip,请把枕头和gym去掉,然后重新安装。如果你觉得很难,你可以用这个命令更容易:

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

$ pip install -I Pillow,gym

此冲突是由于您的 PC 上安装了旧的健身房版本,因此应强制重新安装才能升级。如果这不能解决问题并且最新版本的健身房需要旧版本的 Pillow(正如我在您的问题中所读到的),请使用以下命令安装相应的枕头版本:

$ pip install -I Pillow==7.2.0
,

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

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

brew install zlib 将 zlib 库添加到路径中,“brew info zlib”给出了如何将 zlib 库以及 package-config 文件添加到路径的说明。 对于 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

,

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

pip uninstall pillow
pip install pillow
conda install -c conda-forge gym