简体   繁体   English

ImportError:没有名为 virtualenv 的模块

[英]ImportError: No module named virtualenv

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?有人对我的案子有想法吗?

Install virtualenv using pip install virtualenv .使用pip install virtualenv If you have it already installed, try reinstalling it by removing it with pip uninstall virtualenv and then reinstalling it.如果您已经安装了它,请尝试通过使用pip uninstall virtualenv将其删除然后重新安装来重新安装它。 Good Luck.祝你好运。

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

sudo -H pip install virtualenv

I think the problem is you need sudo to 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).但这会创建只能由 root 读取的文件(取决于 umask)。 In this case, uninstalling/reinstalling may not always help.在这种情况下,卸载/重新安装可能并不总是有帮助。

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

Use pip3 instead of pip.使用 pip3 而不是 pip。 I had the same issue and pip3 worked for me.我有同样的问题,pip3 为我工作。

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

I just ran into this same problem.我刚刚遇到了同样的问题。 I had to pip uninstall virtualenv as a user with admin rights, then pip install virtualenv as a normal user.我必须以具有管理员权限的用户身份pip uninstall virtualenv ,然后以普通用户身份pip install virtualenv I think it's some kind of permissions issue if you installed virtualenv under admin rights.如果您在管理员权限下安装 virtualenv,我认为这是某种权限问题。

尝试

python3 -m pip uninstall virtualenv

python3 -m pip install virtualenv
>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!答对了!

I had the same problem when I created my virtualenv via pycharm and installed requirements with pycharm.当我通过 pycharm 创建我的 virtualenv 并使用 pycharm 安装需求时,我遇到了同样的问题。 After trail and error , I found that installed requirements are not taken into account by the virtualenv.经过跟踪和错误,我发现 virtualenv 没有考虑已安装的要求。

The solution is to reinstall all requirements once you have activated your virtualenv:解决方案是在激活 virtualenv 后重新安装所有要求:

venv\\scripts\\activate venv\\脚本\\激活

python -m pip install -r YourRequirements.txt python -m pip install -r YourRequirements.txt

Next time I'd better create my virtualenv directly with command line下次我最好直接用命令行创建我的 virtualenv

Got this error when using the ansible pip module automating some pip installs on my localhost.使用 ansible pip 模块在我的本地主机上自动安装一些 pip 时出现此错误。

fatal: [localhost]: FAILED! => {"changed": false, "cmd": ["/opt/bin/virtualenv", "--system-site-packages", "-p/usr/bin/python3", "/opt/venv/myenv"], "msg": "\n:stderr: /usr/bin/python3: No module named  virtualenv\n"}

Uninstalling virtualenv python3 -m pip uninstall virtualenv did show virtualenv was installed here /home/ubuntu/.local/bin/virtualenv .卸载 virtualenv python3 -m pip uninstall virtualenv确实显示virtualenv安装在这里/home/ubuntu/.local/bin/virtualenv

In the ansible task specify the virtualenv_command :在 ansible 任务中指定virtualenv_command

- name: install requirements file
  pip:
    virtualenv_command: "/home/{{whoami.stdout}}/.local/bin/virtualenv"
    virtualenv: "/home/{{whoami.stdout}}/.venv/{{item.env.virtualenv}}"
    requirements: "/home/{{whoami.stdout}}/git/{{item.env.requirements_txt}}"
    virtualenv_site_packages: yes
  when: req_stat.stat.exists

For mac os the issue was with virtualenv.对于 mac os,问题出在 virtualenv 上。 This is because the folder virtualenv did not exist.这是因为文件夹 virtualenv 不存在。

This worked well这运作良好

python3 -m venv env

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM