Python 导入错误:没有名为 virtualenv 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21070369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 21:59:04  来源:igfitidea点击:

ImportError: No module named virtualenv

pythondjangowindows-7

提问by gadss

I am using Django 1.3.7 and python 2.7.6 on windows7 I got an error when I executing my manage.py in this line of code

我在 windows7 上使用 Django 1.3.7 和 python 2.7.6 我在这行代码中执行 manage.py 时出错

import shutil, sys, virtualenv, subprocess

amd running it, I got this error

amd 运行它,我收到此错误

C:\Django-Proj\>python manage.py update_ve
Traceback (most recent call last):
  File "manage.py", line 4, in <module>
    import shutil, sys, virtualenv, subprocess
ImportError: No module named virtualenv

Does anyone have an Idea about my case?

有人对我的案子有什么想法吗?

采纳答案by Aurora

Install virtualenv using pip install virtualenv. If you have it already installed, try reinstalling it by removing it with pip uninstall virtualenvand then reinstalling it. Good Luck.

使用pip install virtualenv. 如果您已经安装了它,请尝试通过删除它pip uninstall virtualenv然后重新安装来重新安装它。祝你好运。

回答by brousch

I just ran into this same problem. I had to pip uninstall virtualenvas a user with admin rights, then pip install virtualenvas a normal user. I think it's some kind of permissions issue if you installed virtualenv under admin rights.

我刚刚遇到了同样的问题。我必须pip uninstall virtualenv作为具有管理员权限的用户,然后pip install virtualenv作为普通用户。如果您在管理员权限下安装 virtualenv,我认为这是某种权限问题。

回答by Bailey Smith

I had to install virtualenv with the -H flag to set HOME variable to target user's home dir.

我必须使用 -H 标志安装 virtualenv 才能将 HOME 变量设置为目标用户的主目录。

sudo -H pip install virtualenv

sudo -H pip install virtualenv

回答by jozxyqk

I think the problem is you need sudoto globally install virtualenv.

我认为问题是您需要sudo全局安装 virtualenv。

> pip install virtualenv
Could not find an activated virtualenv (required).
> sudo pip install virtualenv
Downloading/unpacking virtualenv
...

But this creates files readable only by root (depending on the umask). In this case, uninstalling/reinstalling may not always help.

但这会创建只能由 root 读取的文件(取决于 umask)。在这种情况下,卸载/重新安装可能并不总是有帮助。

You can check with ls -la /usr/local/lib/python2.7/dist-packages/virtualenv.py(replacing 2.7 with whatever version you have or are targeting).

您可以检查ls -la /usr/local/lib/python2.7/dist-packages/virtualenv.py(用您拥有或目标的任何版本替换 2.7)。

My solution was simply:

我的解决方案很简单:

sudo chmod -R o+rX /usr/local/lib/python2.7

回答by bitfishxyz

>virtualenv
ImportError: No module named 'virtualenv'
>pip uninstall virtualenv
PermissionError: [Errno 13] Permission denied:

>sudo pip uninstall virtualenv
Successfully uninstalled virtualenv-15.1.0
>pip install virtualenv
Collecting virtualenv

>virtualenv
Options:

Bingo!

答对了!

回答by petitchamp

I had the same problem when I created my virtualenv via pycharm and installed requirements with pycharm. After trail and error , I found that installed requirements are not taken into account by the virtualenv.

当我通过 pycharm 创建我的 virtualenv 并使用 pycharm 安装需求时,我遇到了同样的问题。经过跟踪和错误,我发现 virtualenv 没有考虑已安装的要求。

The solution is to reinstall all requirements once you have activated your virtualenv:

解决方案是在激活 virtualenv 后重新安装所有要求:

venv\scripts\activate

python -m pip install -r YourRequirements.txt

venv\脚本\激活

python -m pip install -r YourRequirements.txt

Next time I'd better create my virtualenv directly with command line

下次我最好直接用命令行创建我的 virtualenv

回答by Chirag Kalal

Use pip3 instead of pip. I had the same issue and pip3 worked for me.

使用 pip3 而不是 pip。我有同样的问题,pip3 为我工作。

$ pip3 install virtualenv
$ virtualenv venv --python=python3