环境 Python3.8
在安装 matplotlib
过程中的问题,遇到了两个报错:
错误一:
Command "python setup.py egg_info" failed with error code 1
错误代码节选:
Complete output from command python setup.py egg_info:
WARNING: The wheel package is not available.
ERROR: Command errored out with exit status 1:
command: 'D:\projects\hope\venv\Scripts\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\admin\\AppData\\Local\\Temp\\pip-wheel-89wmbbu3\\cppy_484570ae596d45f5a128fc3b8d139650\\setup
.py'"'"'; __file__='"'"'C:\\Users\\admin\\AppData\\Local\\Temp\\pip-wheel-89wmbbu3\\cppy_484570ae596d45f5a128fc3b8d139650\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'
\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\admin\AppData\Local\Temp\pip-wheel-7_cuzd9r'
cwd: C:\Users\admin\AppData\Local\Temp\pip-wheel-89wmbbu3\cppy_484570ae596d45f5a128fc3b8d139650\
Complete output (6 lines):
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
error: invalid command 'bdist_wheel'
----------------------------------------
ERROR: Failed building wheel for cppy
ERROR: Failed to build one or more wheels
Traceback (most recent call last):
File "D:\projects\hope\venv\lib\site-packages\setuptools\installer.py", line 126, in fetch_build_egg
subprocess.check_call(cmd)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['D:\\PycharmProjects\\hope\\venv\\Scripts\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\admin\\AppData\\Local\\Temp\\tmprk6fgiey', '-
-quiet', 'cppy>=1.1.0']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\admin\AppData\Local\Temp\pip-install-5tcg9s0l\kiwisolver\setup.py", line 69, in <module>
setup(
File "D:\projects\hope\venv\lib\site-packages\setuptools\__init__.py", line 152, in setup
_install_setup_requires(attrs)
......
File "D:\projects\hope\venv\lib\site-packages\setuptools\installer.py", line 128, in fetch_build_egg
raise DistutilsError(str(e)) from e
distutils.errors.DistutilsError: Command '['D:\\PycharmProjects\\hope\\venv\\Scripts\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\admin\\AppData\\Local\\Temp\\tmprk6fgiey',
'--quiet', 'cppy>=1.1.0']' returned non-zero exit status 1.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\admin\AppData\Local\Temp\pip-install-5tcg9s0l\kiwisolver\
如果从报错的最底部开始,很容易会误以为是因为 "python setup.py egg_info" failed with error code 1
引起,而实际上仔细看上面引起报错的原因:
error: invalid command 'bdist_wheel'
# 再往前
WARNING: The wheel package is not available.
ERROR: Command errored out with exit status 1:
可见,实际上是因为缺少 wheel
这个包。
安装wheel
pip install wheel
错误二
Failed building wheel for matplotlib
Running setup.py clean for matplotlib
Building wheel for kiwisolver (setup.py) ... done
Stored in directory: C:\Users\admin\AppData\Local\pip\Cache\wheels\fe\93\13\827a1e37fc6c6002663925c2423e4f36c51ecbb22c8b9e0da7
Building wheel for pillow (setup.py) ... error
Complete output from command D:\PycharmProjects\hope\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\admin\\AppData\\Local\\Temp\\pip-install-2yli0okj\\pillow\\setup.py';f=getattr(tokenize, 'open'
, open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\admin\AppData\Local\Temp\pip-wheel-_yg0o59b --python-tag cp38:
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.8
creating build\lib.win-amd64-3.8\PIL
copying src\PIL\BdfFontFile.py -> build\lib.win-amd64-3.8\PIL
......
copying src\PIL\_binary.py -> build\lib.win-amd64-3.8\PIL
warning: no previously-included files matching '*.pyc' found anywhere in distribution
warning: no previously-included files matching '*.so' found anywhere in distribution
no previously-included directories found matching '.ci'
writing manifest file 'src\Pillow.egg-info\SOURCES.txt'
running build_ext
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 "C:\Users\admin\AppData\Local\Temp\pip-install-2yli0okj\pillow\setup.py", line 861, in <module>
setup(
File "D:\PycharmProjects\hope\venv\lib\site-packages\setuptools\__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\distutils\core.py", line 148, in setup
dist.run_commands()
......
File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\distutils\command\build_ext.py", line 340, in run
self.build_extensions()
File "C:\Users\admin\AppData\Local\Temp\pip-install-2yli0okj\pillow\setup.py", line 698, 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 "C:\Users\admin\AppData\Local\Temp\pip-install-2yli0okj\pillow\setup.py", line 914, 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
----------------------------------------
Failed building wheel for pillow
Running setup.py clean for pillow
Successfully built kiwisolver
Failed to build matplotlib pillow
Installing collected packages: cycler, kiwisolver, numpy, pillow, pyparsing, matplotlib
Running setup.py install for pillow ... error
Complete output from command D:\PycharmProjects\hope\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\admin\\AppData\\Local\\Temp\\pip-install-2yli0okj\\pillow\\setup.py';f=getattr(tokenize, 'ope
n', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\admin\AppData\Local\Temp\pip-record-d2iw5q_0\install-record.txt --single-version-externally-managed -
-compile --install-headers D:\PycharmProjects\hope\venv\include\site\python3.8\pillow:
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.8
creating build\lib.win-amd64-3.8\PIL
copying src\PIL\BdfFontFile.py -> build\lib.win-amd64-3.8\PIL
copying src\PIL\BlpImagePlugin.py -> build\lib.win-amd64-3.8\PIL
copying src\PIL\DcxImagePlugin.py -> build\lib.win-amd64-3.8\PIL
......
warning: no previously-included files found matching '.readthedocs.yml'
warning: no previously-included files found matching 'codecov.yml'
no previously-included directories found matching '.ci'
writing manifest file 'src\Pillow.egg-info\SOURCES.txt'
running build_ext
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 "C:\Users\admin\AppData\Local\Temp\pip-install-2yli0okj\pillow\setup.py", line 861, in <module>
setup(
File "D:\PycharmProjects\hope\venv\lib\site-packages\setuptools\__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\distutils\core.py", line 148, in setup
dist.run_commands()
......
File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\distutils\command\build_ext.py", line 340, in run
self.build_extensions()
File "C:\Users\admin\AppData\Local\Temp\pip-install-2yli0okj\pillow\setup.py", line 698, 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 "C:\Users\admin\AppData\Local\Temp\pip-install-2yli0okj\pillow\setup.py", line 914, 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
----------------------------------------
Command "D:\PycharmProjects\hope\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\admin\\AppData\\Local\\Temp\\pip-install-2yli0okj\\pillow\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code
=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\admin\AppData\Local\Temp\pip-record-d2iw5q_0\install-record.txt --single-version-externally-managed --compile --install-heade
rs D:\PycharmProjects\hope\venv\include\site\python3.8\pillow" failed with error code 1 in C:\Users\admin\AppData\Local\Temp\pip-install-2yli0okj\pillow\
一番查找,会发现这个错误的原因是由
Failed building wheel for pillow
这里开始引起的,脚本自己生成 wheel
失败,那我们就去下载 whl
自己下载安装文件,手动安装,这里提供一个下载 whl
包的地方:
https://www.lfd.uci.edu/~gohlke/pythonlibs/
这里我下载一个对应 Python3.8
的包:
Pillow-8.0.1-cp38-cp38-win_amd64.whl
直接安装:
pip install Pillow-8.0.1-cp38-cp38-win_amd64.whl
会提示错误:
Pillow-8.0.1-cp38-cp38-win_amd64.whl is not a supported wheel on this platform.
同样的错误也会出现在 matplotlib
的 whl
包安装过程中:
matplotlib-3.3.3-cp38-cp38-win_amd64.whl is not a supported wheel on this platform.
确认自己版本没有下载错误,然后把包名中第二个 cp38 改成 none 即可安装,改过之后的包名类似这样:
Pillow-8.0.1-cp38-none-win_amd64.whl
然后就可以顺利将 matplotlib
安装成功了。
直接装anaconda
我在用pycharm了,用香港服务器配同样的环境,统统都没问题,贼6