110

I was creating a new virtual environment on Ubuntu 20.04:

$ virtualenv my_env

But it gave an error:

ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data'

Other info:

$ virtualenv --version
virtualenv 20.0.17 from /usr/lib/python3/dist-packages/virtualenv/__init__.py
Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
Tung Ng.
  • 1,241
  • 2
  • 8
  • 12
  • 9
    for those of you using poetry & on Ubuntu 20.04 or its variant [this](https://github.com/python-poetry/poetry/issues/2972) thread on github helped me solve my problem. – Umar.H Mar 08 '21 at 07:34
  • 8
    Thanks @Umar.H, that worked for me with poetry on (Ubuntu-based) Mint 20.2 (tl;dr: `sudo apt remove --purge python3-virtualenv`) – Andrew Richards Jan 18 '22 at 17:56

15 Answers15

136

@yushulx I also ran into the same issue. I installed both via pip3 and via sudo apt install python3-virtualenv and it gave me an error but after I ran pip3 uninstall virtualenv I could create a virtualenv without issue

iulian
  • 5,494
  • 3
  • 29
  • 39
misinglink
  • 1,469
  • 2
  • 5
  • 6
  • 8
    I did vice-versa `sudo apt remove python3-virtualenv` and that worked as well. Clearly a result of mixing those up. – Yuri Feldman Jun 12 '22 at 07:55
63

Try to create the virtual environment using directly venv module

python3 -m venv my_env
isalgueiro
  • 1,973
  • 16
  • 20
  • 2
    Can't this problem be fixed? – Manish Shah Sep 03 '20 at 20:50
  • I think `virtualenv` is using a different python installation that your `python3` default installation, thus the ModuleNotFoundError. Easiest way to get around this is to use directly venv python 3 module. I don't know from the top of my head how to make virtualenv tool use the same python environment as `python3` link is using. – isalgueiro Sep 04 '20 at 15:20
  • 3
    To activate `source my_env/bin/activate` – Yogesh Kushwaha Mar 16 '21 at 09:32
50

To fix this on Ubuntu 20.04, I had to uninstall virtualenv from the system: apt remove python3-virtualenv, and reinstall it using pip: pip install --user virtualenv --force-reinstall. I had errors about dependencies conflicts, I fixed them by calling pip install --user ${package} --force-reinstall for every package involved.

Victor Paléologue
  • 2,025
  • 1
  • 17
  • 27
32

virtualenv is installed by default with python itself and when you install virtualenv via pip3 and try to create virtual environment using pipenv you will get this error:

ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data

Check the version of installed virtualenv using apt list --installed:

python3-virtualenv/focal,focal,now 20.0.17-1 all [installed,automatic] with the installed virtualenv by pip3:

virtualenv             20.4.0

Default installation of virtualenv is different with pip3 installed virtualenv

So when you try to create a virtual environment using pipenv (for example installing Django in a directory home/user/django with pipenv install django~=3.1.5 you will get that error.

The solution is to remove installed virtualenv using pip3 uninstall virtualenv and use the default installation of virtualenv. This time when you create virtual environment with pipenv it will create it successfully.

The Godfather
  • 4,235
  • 4
  • 39
  • 61
Edalat Feizi
  • 1,371
  • 20
  • 32
17

I want to have virtualenvwrapper. On Debian 10 testing I did:

apt remove python3-virtualenvwrapper  # not purge, I want no changes in ~/.virtualenvs/
apt purge python3-virtualenv
/usr/bin/python3.8 -m pip install --force-reinstall virtualenvwrapper
/usr/bin/python3.8 -m pip install --force-reinstall virtualenv==20.0.23

.24 no longer works. I hope it will be solved sometimes...

EDIT 2021.01: I have changed my stack to: pyenv + pyenv-virtualenvwrapper + poetry. Ie. I use no apt or pip installation of virtualenv or virtualenvwrapper, and instead I install pyenv's plugin pyenv-virtualenvwrapper. This is easier way.

mirek
  • 1,140
  • 11
  • 10
  • 1
    note: Seems if you have the "apt..." installation, removing/purging is not required. Just apply the last command with ...==20.0.23 and it should be enough. – mirek Oct 02 '20 at 16:49
  • + I had more troubles later (I am not sure what I made before), mkvirtualenv was no longer found, previous gave the error "No module found.." again. I was then successfull with user (ie. not root) installation only. :( – mirek Oct 14 '20 at 11:49
  • .... so I had often some troubles with apt or pip installation of virtualenv+virtualenvwrapper. At this time the combination of pyenv + its virtualenvwrapper plugin (without apt or pip install) looks good for me. For details read my answer here: https://stackoverflow.com/a/65465391/2520298 – mirek Dec 27 '20 at 11:55
8

If someone encounters this problem inside existing env (when for example using pyenv) you can also use command below (found on GitHub when tried to fix poetry virtual env installation):

pip install --force-reinstall virtualenv
devaerial
  • 2,069
  • 3
  • 19
  • 33
5

I also had same issue, seems installed version has different user level so I followed their doc and below one work for me:

python3 -m virtualenv --help

To create new environment:

python3 -m virtualenv my_env
Damith Asanka
  • 934
  • 10
  • 12
4

When I installed virtualenv via pip3, it failed to run virtualenv command. Then I changed the installation via:

sudo apt install python3-virtualenv

The virtualenv command can normally work.

yushulx
  • 11,695
  • 8
  • 37
  • 64
  • This worked for me. Actually a lot of mess is around due to python2 & 3 and this was on the top of it. – pankaj Dec 12 '20 at 12:19
4

I too had this issue. What I found is it is a permissions issue. For some unknown reason ownership of my home directory was off. I did a chown -R for the directory I was using for my project making myself the owner of my own directory and now everything works as normal.

Ruli
  • 2,592
  • 12
  • 30
  • 40
3

I also faced the same issue but after removing virtualenv which was installed with pip3, I could get rid of this error. Uninstall virtualenv with below command (don't forget to use sudo)

sudo pip3 uninstall virtualenv

After this, virtualenv command works totally fine.

RITI
  • 51
  • 3
1

It means that there are two virtualenv in your system. One is "pip install" by sudo or root, the other may be installed by apt(if you are using ubuntu os) Just uninstall one of them and the error should be fixed.

Eric
  • 21
  • 1
1

I fixed this error by removing all virtualenv and virtualenvwrapper related packages on system and reinstall the virtualenv and virtualenvwrapper with pip with below command(as i use ubuntu, so below only show apt) remove all packages shown in below result

apt list --installed | grep virtualenvwrapper 
apt list --installed | grep virtualenvwrapper 

install virtualenv virtualenvwrapper with pip

pip install virtualenvwrapper virtualenvwrapper 

set ~/.zshrc

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/amd
export VIRTUALENVWRAPPER_SCRIPT=/home/robot/.local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
source /home/robot/.local/bin/virtualenvwrapper.sh
xiaojueguan
  • 870
  • 10
  • 19
1

When we use pip3 or python3 to install virtualenv then I got that error too. I had to run each time to create virtualenv (my_env is virtual environment name)

python3 -m virtualenv my_env

But if I install it using

sudo apt install virtualenv

Then virtualenv command works fine.

virtualenv my_env
Saikat Roy
  • 502
  • 8
  • 20
1

Install venv package using this command

sudo apt install python3.8-venv

Create virtual environment using this command

python3 -m venv env

Activate virtual environment using this command

source my_env/bin/activate

Decative virtual environment using this command

deactivate
Aashish Kumar
  • 111
  • 1
  • 5
0

if you have tried to install using pip command earlier uninstall

pip uninstall virtualenv

then try to create virtual env

virtualenv my_name
prince
  • 1