1. 问题错误信息:
执行命令: virtualenv -p /usr/bin/python3.8 py3env , 创建py3env的python3.8的虚拟环境
错误信息:
Running virtualenv with interpreter /usr/bin/python3.8
Using base prefix '/usr/local/python3'
/usr/lib/python3/dist-packages/virtualenv.py:1082: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
New python executable in /home/mi/work/WALL-E/code/walle_new/py3env/bin/python3.8
Also creating executable in /home/mi/work/WALL-E/code/walle_new/py3env/bin/python
Installing setuptools, pkg_resources, pip, wheel...
Complete output from command /home/mi/work/WALL-E...py3env/bin/python3.8 - setuptools pkg_resources pip wheel:
Exception:
Traceback (most recent call last):
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/commands/install.py", line 267, in run
with self._build_session(options) as session:
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/basecommand.py", line 66, in _build_session
session = PipSession(
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/download.py", line 321, in __init__
self.headers["User-Agent"] = user_agent()
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/download.py", line 93, in user_agent
zip(["name", "version", "id"], platform.linux_distribution()),
AttributeError: module 'platform' has no attribute 'linux_distribution'
Traceback (most recent call last):
File "<stdin>", line 24, in <module>
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/__init__.py", line 217, in main
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/basecommand.py", line 242, in main
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/basecommand.py", line 66, in _build_session
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/download.py", line 321, in __init__
File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/download.py", line 93, in user_agent
AttributeError: module 'platform' has no attribute 'linux_distribution'
----------------------------------------
...Installing setuptools, pkg_resources, pip, wheel...done.
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/virtualenv.py", line 2363, in <module>
main()
File "/usr/lib/python3/dist-packages/virtualenv.py", line 709, in main
create_environment(home_dir,
File "/usr/lib/python3/dist-packages/virtualenv.py", line 984, in create_environment
install_wheel(
File "/usr/lib/python3/dist-packages/virtualenv.py", line 918, in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File "/usr/lib/python3/dist-packages/virtualenv.py", line 810, in call_subprocess
raise OSError(
OSError: Command /home/mi/work/WALL-E...py3env/bin/python3.8 - setuptools pkg_resources pip wheel failed with error code 1
2.问题解决思路:
从上面可知,关键信息:AttributeError: module 'platform' has no attribute 'linux_distribution'
原因是:https://blog.csdn.net/qq_42415326/article/details/104767193
python3.7以后platform.linux_distribution()被移除了。
(详见https://docs.python.org/3.5/library/platform.html#platform.linux_distribution)
那安装wheel却走到了此方法,想着进入“/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/download.py”, 修改为“distro.linux_distribution()”。 无奈是一个pip-8.1.1-py2.py3-none-any.whl是一个文件而非目录。
wheel文件是什么???
wheel 是新的 Python 的 disribution,用于替代 Python 传统的 egg 文件。目前有超过一半的库文件有对应的 wheel 文件。
*.whl文件有一点与*.egg文件相似:实际上它们都是“伪装的”*.zip文件。如果你将*.whl文件名扩展改为*.zip,你就可以使用你的zip应用程序打开它,并且可以查看它包含的文件和文件夹。
那么按上面,应该是系统的wheel文件比较老了,采用的是python3.7之前来实现的,那么应该替换一个新的。
https://www.lfd.uci.edu/~gohlke/pythonlibs/这里有系统的wheel文件,下载一个最新的pip-20.0.2-py2.py3-none-any.whl,更名为系统中的pip-8.1.1-py2.py3-none-any.whl,替换系统的pip-8.1.1-py2.py3-none-any.whl文件。
virtualenv -p /usr/bin/python3.8 py3env
Running virtualenv with interpreter /usr/bin/python3.8
Using base prefix '/usr/local/python3'
/usr/lib/python3/dist-packages/virtualenv.py:1082: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
New python executable in /home/mi/work/WALL-E/code/walle_new/py3env/bin/python3.8
Also creating executable in /home/mi/work/WALL-E/code/walle_new/py3env/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
成功了!!!