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.
virtualenv
Running virtualenv with interpreter /usr/bin/python2
You can specify the Python interpreter to use with the
-p
option:This will use the default Python 3 interpreter currently installed on your system.
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
Install Python 3 virtual environment creator
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.
The new Python virtual environment for python3.7 will be created in the
env
directory which is located in the current directory.Install Python packages.
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.
Open an existing Python project. In the below screenshot the project is named plot-line. It plots a line in a separate window.
Click the plot-line configuration dropdown triangle which is marked by a green arrow in the below screenshot.
From the popup context menu select Edit Configurations. A new Run/Debug Configurations window will appear.
In the Run/Debug Configurations window click the Configuration tab.
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.
configure path to Python interpreter in PyCharm Community Edition 2019.2