电脑上安装的python包很多,但不是碰到报错基本就没升级过。今天将所有包升级了一下,发现了几种类型的错误,本文整理备忘。
首先,获取全部过期的/可升级的包的列表:pip list --outdated
然后,分别为每一个包准备一行命令:pip install -U xxx
,不能将全部的包的名称写到后面,因为为避免依赖错误,pip的升级策略是先下载全部的包,再统一安装,而一旦某个包下载错误,命令就终止了。
下面是遇到的几类错误:
版本不符:
ERROR: astroid requires Python '>=3.4.*' but the running Python is 2.7.12
ERROR: jupyter-console requires Python '>=3.5' but the running Python is 2.7.12
无法卸载distutils安装的旧版本:
ERROR: Cannot uninstall 'appinst'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
ERROR: Cannot uninstall 'casuarius'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
解决办法是先从/Python27/Lib/site-packages/
目录手动删除旧的包再安装,也可以尝试pip install -U xxx --ignore-installed xxx
。
依赖错误:
不是缺少某个依赖,而是某个依赖已经安装,但版本不符,pip不能武断地升级依赖。
ERROR: google-gax 0.16.0 has requirement ply==3.8, but you'll have ply 3.11 which is incompatible.
ERROR: google-gax 0.16.0 has requirement future<0.17dev,>=0.16.0, but you'll have future 0.17.1 which is incompatible.
解决办法是单独升级依赖,或者全部命令跑完后,再将错误的重新跑一遍,因为此时那些被依赖的通常已经升级完毕了。
egg_info错误:
ERROR: Command "python setup.py egg_info" failed with error code 1 in c:\users\qiushan\appdata\local\temp\pip-install-xrybv2\enable\
ERROR: Command "python setup.py egg_info" failed with error code 1 in c:\users\qiushan\appdata\local\temp\pip-install-ouy96h\ipython\
文件运行错误:
ERROR: Command "'c:\python27\python.exe' 'c:\python27\lib\site-packages\pip\_vendor\pep517\_in_process.py' get_requires_for_build_wheel 'c:\users\qiushan\appdata\local\temp\tmpji4gae'" failed with error code 1 in c:\users\qiushan\appdata\local\temp\pip-install-qra1dr\scipy
ERROR: Command "'c:\python27\python.exe' 'c:\python27\lib\site-packages\pip' install --ignore-installed --no-user --prefix 'c:\users\qiushan\appdata\local\temp\pip-build-env-nxt0oj\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.doubanio.com/simple --trusted-host pypi.doubanio.com -- setuptools wheel 'ipython>=5' 'jupyter_core>=4.2' jupyter_client" failed with error code 1 in None
文件校验错误:
ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
环境错误:
ERROR: Could not install packages due to an EnvironmentError: [Error 5] : 'c:\\\python27\\lib\\site-packages\\~crypt\\_bcrypt.pyd'
ERROR: Could not install packages due to an EnvironmentError: [Error 5] : 'c:\\\python27\\lib\\site-packages\\~ryptography\\hazmat\\bindings\\_constant_time.pyd'
中断错误:
ERROR: Operation cancelled by user
-- EOF --
本文最后修改于6年前 (2019-06-01)