我正在使用CentOS 7,并希望运行“ virtualenv”命令。所以我尝试卸载并重新安装它。
[myuser@server ~]$ sudo pip uninstall virtualenv
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Cannot uninstall 'virtualenv'. 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.
[myuser@server ~]$ sudo pip install virtualenv
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already satisfied: virtualenv in /usr/lib/python2.7/site-packages (15.1.0)
但是当我去实际运行它时,会告诉我它没有安装。
[myuser@server ~]$ virtualenv myenv
Traceback (most recent call last):
File "/usr/bin/virtualenv", line 2, in <module>
import virtualenv
ModuleNotFoundError: No module named 'virtualenv'
WTF?
答案 0 :(得分:1)
您只需删除virtualenv rm -r ./your_venv
,然后创建一个新的python3 -m virtualenv your_venv
并激活此source ./your_venv/bin/activate
。现在您处于分离的环境中。例如,在这种状态下,您可以安装库pip install -r ./requirements.txt
。这些库将仅安装在您的环境内部,而不是全局。
答案 1 :(得分:0)
尝试python -m virtualenv myenv
。 -m
标志表示模块。使用此命令,您明确地告诉python将模块virtualenv
作为脚本运行。