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?

2

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

4 Comments

Thanks this did the job, but what about pip?
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
I meant to ask how to I specify the pip location/version?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.