[英]Installed virtualenv, but still getting “ModuleNotFoundError: No module named 'virtualenv'” error
I'm using CentOS 7 and want to run a "virtualenv" command. 我正在使用CentOS 7,并希望运行“ virtualenv”命令。 So I tried uninstalling and re-installing it ...
所以我尝试卸载并重新安装它...
[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)
but when I go to actually run it, I'm told its not installed. 但是当我去实际运行它时,被告知它没有安装。
[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?? WTF?
You can just remove virtualenv rm -r ./your_venv
and after that create new one python3 -m virtualenv your_venv
and activate this source ./your_venv/bin/activate
. 您可以只删除virtualenv
rm -r ./your_venv
,然后创建一个新的python3 -m virtualenv your_venv
并激活此source ./your_venv/bin/activate
。 Now you are in separated environment. 现在您处于分离的环境中。 In this state you can install your libs
pip install -r ./requirements.txt
for example. 例如,在这种状态下,您可以安装libs
pip install -r ./requirements.txt
。 The libs are going to install only inside your environment, not globally. 这些库将仅安装在您的环境内部,而不是全局安装。
try python -m virtualenv myenv
. 尝试
python -m virtualenv myenv
。 The -m
flag means module. -m
标志表示模块。 With this command, you are explicitly telling python to run the module virtualenv
as a script. 使用此命令,您明确地告诉python将脚本
virtualenv
作为脚本运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.