TheOne
TheOne

Reputation: 11159

Python3 virtualenv installs python2

I am not sure what is wrong but I can't seem to get python3 in a virtualenv environment. I tried upgrading my ubuntu and updating all the packages - but no luck:

python3 -m virtualenv ENV
Running virtualenv with interpreter /usr/bin/python2
New python executable in /home/ramin/projects/buybulkamerica/ENV/bin/python2
Also creating executable in /home/ramin/projects/buybulkamerica/ENV/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.

What can I do to ensure that virtualenv installs python3 instead of python2?

Upvotes: 0

Views: 4423

Answers (2)

vishal
vishal

Reputation: 1205

First, uninstall existing virtualenv.

sudo apt-get remove --purge python-virtualenv if you installed it using a package manager.

pip uninstall virtualenv if you have installed it using pip.

pip3 uninstall virtualenv if you have installed it using pip3.

Any one of the above commands will work.

Now install virtualenv again. Since you want python3, you need to run the following command.

pip3 install virtualenv

That should do the trick. Now when you create a new virtualenv, it will use python3.

There may be a better way but I had the same problem and after not finding any solution I tried this and it worked.

Upvotes: 2

Teemu
Teemu

Reputation: 286

After you have installed virtualenv using pip, it doesn't matter if you used pip or pip3 if you give the location of your python3 installation to the virtualenv command, like this.

Create new virtualenv virtualenv --python=/usr/bin/python3.6 environmentname

Access virtualenv source /environmentname/bin/activate

If this doesn't work, use complete path from pwd

source /complete/path/to/environmentname/bin/activate

Stop virtualenv deactivate

Upvotes: 0

Related Questions