ImportError: No module named virtualenv
Asked Answered
C

12

91

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?

Crocker answered 12/1, 2014 at 1:56 Comment(1)
Looks like Django manage.py requires that virtualenv is installed. Have you got it installed?Hazem
A
132

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.

Accepted answered 12/1, 2014 at 4:34 Comment(6)
This worked for me on OS X using the MacPorts Python. Although MacPorts includes ports for virtualenv and virtualenvwrapper, they are outdated. So pip bundled with virtualenv is outdated, mandating uninstalling the MacPorts one and using pip to install the latest virtualenv. For details, for any MacPorts users that run into the same issue, see here.Statfarad
On ubuntu, I noticed that even pip install vitualenv is successful, when I execute the command to create one, it keeps saying there's no virtualenv installed and suggesting use apt to install. Should I give it a try?Seften
Also found I had a subborn /usr/local/bin/virtualenv binary that wouldn't delete via pip uninstall, so a sudo rm -f on that did the trick, then did a normal user pip install and finally got things to work.Raver
Works perfectly :DReject
@Shad, on Ubuntu, it probably defaults to python3, so try: sudo pip3 install virtualenvLarimore
pip install virtualenv doesn't work. pip uninstall virtualenv also doesn't work: pip says "Cannot uninstall requirement virtualenv, not installed".Martines
D
23

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

sudo -H pip install virtualenv

Dextrorse answered 16/4, 2016 at 14:33 Comment(1)
sudo pip install virtualenv (with no -H) worked for me on KDE neon 5.26 .Devilkin
B
13

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

$ pip3 install virtualenv
$ virtualenv venv --python=python3
Baalman answered 24/6, 2019 at 12:28 Comment(1)
I didn't have pip on my system, and working with pip3 did the trick.Devilkin
S
13

Try

python3 -m pip uninstall virtualenv

python3 -m pip install virtualenv
Slackjawed answered 4/12, 2020 at 3:11 Comment(2)
It works, while what's the difference between pip3 uninstall virtualenv and python3 -m pip uninstall virtualenv?Shoer
@Shoer They should be the same, but using python3 -m pip will ensure you are calling pip for your python3 interpreter, and not some pip3 that might be outdated or installed by the OS or something else unexpected.Lachman
S
12

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
Spermophile answered 1/11, 2016 at 0:1 Comment(2)
This worked for me. In my case virtualenv was installed as root; but not accessible by another unprivileged userInnuendo
I had this error, No module named 'virtualenv.seed'; 'virtualenv' is not a package This solution worked for me, virtualenv was installed as a root, but it did not work for some reason until I changed the chmod as mentioned above.Rosyrot
R
5

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.

Requisite answered 14/2, 2014 at 19:10 Comment(0)
B
3

For mac os the issue was with virtualenv. This is because the folder virtualenv did not exist.

This worked well

python3 -m venv env

Bantamweight answered 13/8, 2022 at 4:58 Comment(0)
W
0
>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!

Wit answered 21/1, 2018 at 2:5 Comment(0)
K
0

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

Kurd answered 5/3, 2018 at 14:26 Comment(0)
C
0

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
Calf answered 17/12, 2021 at 1:43 Comment(0)
M
0

Poetry wants to be in venv by default so I used venv in docker. I got the error randomly after multiple month of using that setup.

If this is the case for you, just don't use venv in docker. You can turn off venv requirement for poetry by: /usr/bin/poetry config virtualenvs.create false.

It is also possible to export poetry into requirements.txt by poetry export -f requirements.txt --output requirements.txt.

Midwifery answered 1/4, 2023 at 10:58 Comment(0)
S
0

sudo apt install python3-virtualenv

worked for me: (WSL env)

sudo apt install python3-virtualenv

Scrutineer answered 18/9, 2023 at 7:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.