ImportError: No module named virtualenv

PythonDjangoWindows 7

Python Problem Overview


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

import shutil, sys, virtualenv, subprocess

amd running it, I got this error

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?

Python Solutions


Solution 1 - Python

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

Solution 2 - Python

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

sudo -H pip install virtualenv

Solution 3 - Python

I think the problem is you need sudo to globally install 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.

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).

My solution was simply:

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

Solution 4 - Python

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

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

Solution 5 - Python

Try

python3 -m pip uninstall virtualenv

python3 -m pip install virtualenv

Solution 6 - Python

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. I think it's some kind of permissions issue if you installed virtualenv under admin rights.

Solution 7 - Python

>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!

Solution 8 - Python

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.

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

> venv\scripts\activate > > python -m pip install -r YourRequirements.txt

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

Solution 9 - Python

Got this error when using the ansible pip module automating some pip installs on my localhost.

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.

In the ansible task specify the 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongadssView Question on Stackoverflow
Solution 1 - PythonAuroraView Answer on Stackoverflow
Solution 2 - PythonBailey SmithView Answer on Stackoverflow
Solution 3 - PythonjozxyqkView Answer on Stackoverflow
Solution 4 - PythonChirag KalalView Answer on Stackoverflow
Solution 5 - PythonshanwuView Answer on Stackoverflow
Solution 6 - PythonbrouschView Answer on Stackoverflow
Solution 7 - PythonbytefishView Answer on Stackoverflow
Solution 8 - PythonpetitchampView Answer on Stackoverflow
Solution 9 - PythonsteepestascentView Answer on Stackoverflow