In Ubuntu 16.04 the latest release of Python3 is 3.5. If I just do virutalenv venv
it would create a new virtual environment using Python 3.5.
I followed the instructions in https://linuxize.com/post/how-to-install-python-3-8-on-ubuntu-18-04/ and installed Python 3.8 with apt
from the deadsnakes PPA. But I am still not able to create a Python 3.8 virtual environment. If I do virtualenv --python=/usr/bin/python3.8
, I got this:
user@host:~$ virtualenv --python=/usr/bin/python3.8 venv
RuntimeError: failed to query /usr/bin/python3.8 with code 1 err: 'Traceback (most recent call last):\n File "/usr/local/lib/python3.5/dist-packages/virtualenv/discovery/py_info.py", line 16, in <module>\n from distutils import dist\nImportError: cannot import name \'dist\' from \'distutils\' (/usr/lib/python3.8/distutils/__init__.py)\n'
I noticed that the deadsnakes ppa has instructions that include this:
python#.#-venv
: provides the standard library venv
moduleSo, I believe you need to make sure to apt install python3.8-venv
. Then the following will work:
python3.8 -m venv venv_dir
If you really want to use virtualenv
and not just the native venv
, then you could install it, but you would first need pip
. So the process would look something like this:
python3.8 -m ensurepip
python3.8 -m pip install virtualenv
python3.8 -m virtualenv venv_dir
I hope this helps! In case you want to read (and review/critique, as I would welcome it) I have written a summary of several Python virtual environment tools you may find helpful. Feel free to tell me how I can make it better.
Try using the built-in venv
module instead of virtualenv
:
/usr/bin/python3.8 -m venv virtualenv_directory/
venv
has been included with Python since version 3.3.
I have Ubuntu 20.04lts, and I believe that everyone will be benefited from this solution. I wanted to create a virtual environment for Python 3.8 to use in Pycharm. First-
sudo apt install python3.8-venv
then-
/usr/bin/python3.8 -m venv virtualenv_directory/
This will make the virtual environment. Then follow the link to use in PyCharm - link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With