0

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?

TheOne
  • 10,819
  • 20
  • 81
  • 119
  • Is this helping? https://stackoverflow.com/questions/23842713/using-python-3-in-virtualenv I could reproduce your problem and running it as in the accepted answer worked for me. – T.Nel Jul 26 '18 at 09:04
  • Possible duplicate of [Using Python 3 in virtualenv](https://stackoverflow.com/questions/23842713/using-python-3-in-virtualenv) – phd Jul 26 '18 at 12:17

2 Answers2

2

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.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
vishal
  • 1,081
  • 2
  • 10
  • 27
0

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

Teemu
  • 286
  • 1
  • 2
  • 10
  • Thanks this did the job, but what about pip? – TheOne Jul 26 '18 at 20:55
  • What about pip? Do you mean pip inside the virtualenv? It should be installed when you create the virtualenv, and then you can install any modules into the virtualenv when you have it activated – Teemu Jul 27 '18 at 05:22
  • I meant to ask how to I specify the pip location/version? – TheOne Jul 27 '18 at 08:43
  • https://stackoverflow.com/questions/41688016/update-pip3-for-python-3-6 something like this? – Teemu Jul 27 '18 at 08:53