When type virtualenv in the cmd this comes up:

running virtualenv with interpreter /usr/bin/python2

How do you change the interpreter to the most updated to version of python3?

virtualenv -p python3 ...

Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/name/.../bin/python3
Not overwriting existing python script /home/name/.../bin/python (you must use /home/name/.../bin/python3)
Installing setuptools, pkg_resources, pip, wheel...done.

Running virtualenv with interpreter /usr/bin/python2

The way to install Python 3.x packages in a Python virtual environment is to create the Python virtual environment using Python 3 virtual environment creator (python3-virtualenv). python3-virtualenv is in the default Ubuntu repositories in all currently supported versions of Ubuntu.

Delete an existing Python virtual environment

Simply delete the folder that contains the Python virtual environment. For example if the folder is named venv delete the entire folder and everything in it.

Install Python 3.x packages in a Python virtual environment

  1. Install Python 3 virtual environment creator

    sudo apt install virtualenv python3-virtualenv
  2. Create a Python virtual environment for python3.7. You can only install python3 packages inside this Python virtual environment. If you also want to install Python 2.x packages, then you need to make another Python virtual environment.

    virtualenv -p python3.7 env  
    source ./env/bin/activate

    The new Python virtual environment for python3.7 will be created in the env directory which is located in the current directory.

  3. Install Python packages.

    cd /path/to/env/ # env is the python3.7 virtual environment's directory
    source bin/activate
    python3 -m pip install first-package-name next-package-name last-package-name

This is a new python3.7 virtual environment with the latest version of pip3, so installing Python packages in it will work great.

Bonus - How to select the python3.7 interpreter in PyCharm

In PyCharm each project gets its own Python virtual environment, so you can custom select a different Python version for each project in the project's settings. It works the same as in any other Python virtual environment, except in PyCharm you can use the GUI to choose the Python interpreter version whereas in the Python virtual environment you choose the Python interpreter version from the terminal when you make the Python virtual environment.

  1. Open an existing Python project. In the below screenshot the project is named plot-line. It plots a line in a separate window.

  2. Click the plot-line configuration dropdown triangle which is marked by a green arrow in the below screenshot.

  3. From the popup context menu select Edit Configurations. A new Run/Debug Configurations window will appear.

  4. In the Run/Debug Configurations window click the Configuration tab.

  5. On the right side of the Python interpreter field is a dropdown triangle that when clicked brings up a context menu that allows you to change the Python interpreter.

    PyCharm Community Edition 2019.2
    configure path to Python interpreter in PyCharm Community Edition 2019.2

  • PyCharm has no issue finding and installing Django and running venv in the terminal. – SeemsToBeStuck Sep 11 '19 at 14:28
  • That's good news. If Django runs in the terminal and not in the external Python virtual environment you are right in thinking that there must be something wrong with the Python virtual environment, not with the Python code. – karel Sep 11 '19 at 14:30
  • You've guessed it, what exactly do I do now? – SeemsToBeStuck Sep 11 '19 at 17:00
  • The Python virtual environments gets its DNA from its parents (the user who created it) at birth (when it is created). If there was a way to fix a broken Python virtual environment I would probably know it because I have tried (and failed). If a Python virtual environment is broken it needs to be deleted and a new one should be created. – karel Sep 11 '19 at 17:17

You can specify the Python interpreter to use with the -p option:

virtualenv -p python3 ...

This will use the default Python 3 interpreter currently installed on your system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.