您好,我是Python的初学者。我不记得何时以及如何在我的Macbook Air上安装了Python 3.8,只知道其安装路径:
% which python
/usr/bin/python
% which python3
/usr/local/bin/python3
pip命令无法找到,但pip3可以使用。今天我想安装虚拟环境:
% sudo -H pip3 install virtualenv
WARNING: Ignoring invalid distribution - (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages)
Successfully installed virtualenv-20.6.0
我可以使用“pip3 show virtualenv”来获取信息:
% pip3 show virtualenv
Name: virtualenv
Version: 20.6.0
Summary: Virtual Python Environment builder
Home-page: https://virtualenv.pypa.io/
Author: Bernat Gabor
Author-email: gaborjbernat@gmail.com
License: MIT
Location: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
Requires: six, platformdirs, backports.entry-points-selectable, distlib, filelock
Required-by:
但是当我使用 "virtualenv" 时,我收到了“命令未找到”的消息,然后我进行了 "pip3 uninstall"。我搜索了一下,得到了一个提示,建议使用 "easy_install" 安装 virtualenv。安装后,我可以执行该命令,但是会收到一些错误消息:
% virtualenv
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 6, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module>
@_call_aside
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3225, in _call_aside
f(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3254, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 583, in _build_master
ws.require(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 900, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 786, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'importlib-resources>=1.0' distribution was not found and is required by virtualenv
看起来虚拟环境并没有工作,我尝试使用“sudo pip3 uninstall virtualenv”成功卸载了它,但似乎并没有真正被删除:
% which virtualenv
/usr/local/bin/virtualenv
我不知道这个,你能帮我吗?我只想正常运行virtualenv并创建flask项目...
附注:我可以“sudo pip3 install flask”和“pip3 show flask”,但仍然无法运行flask命令(找不到命令),我该怎么办?
非常感谢!