10

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'
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
fhcat
  • 971
  • 2
  • 9
  • 28

4 Answers4

14

I noticed that the deadsnakes ppa has instructions that include this:

  • python#.#-venv: provides the standard library venv module

So, 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.

jdbow75
  • 497
  • 3
  • 9
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

2

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.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 2
    I got an error running it. ` user@host:~$ /usr/bin/python3.8 -m venv virtualenv_directory Error: Command '['/home/user/virtualenv_directory/bin/python3.8', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1. ` – fhcat Jul 25 '20 at 16:52
  • @fhcat, do you have internet access on this machine? – ChrisGPT was on strike Jul 25 '20 at 23:14
0

The deadsnakes repo is no longer available for Ubuntu 16.04. See my answer here how to install a recent python version via pyenv.

itsafire
  • 5,607
  • 3
  • 37
  • 48