I received this error after upgrading Ubuntu 18.04 LTS to 20.04 LTS. So there were two problems all at once. First the python version was still running 2.x and doing a simple update or try to uninstall (apt-get remove virtualenv
) of virtualenv did not help at all. But I found a solution. First let 20.04 LTS 'know' the times of using old python is over:
sudo apt-get install python-is-python3
Then test it and open a console to get the version string with python -V
; by now it should be showing something like Python 3.8.5. Fine.
Next step is to solve the virtualenv
problem. I tried to find out, which executable was run with which virtualenv
and it showed: $HOME/.local/bin/virtualenv
. Hmmkay, somehow the system wasn't using the /usr/bin/virtualenv
executable. I thought maybe I let the directory become invisible (a.k.a. renaming) and maybe the system will go on a hunt for an alternative virtualenv
running:
mv $HOME/.local/bin/virtualenv /home/$USER/.local/bin/virtualenv_OLD
Then I simply changed into a playground-directory and ran virtualenv donaldknuth
and behold - it worked. To be sure I ran another which virtualenv
and the system returned a /usr/bin/virtualenv
. Last check to do was activating the new virtual environment:
source $HOME/playground/donaldknuth/bin/activate
The terminal changed and it worked fine. Solution
EDIT:
Based on Pierre B.'s suggestion you may have to restart your Shell. The command hash -d virtualenv
will delete the stored location of virtualenv
from the shell's cache and determine the correct path right now. (Sources: https://www.computerhope.com/unix/bash/hash.htm, https://unix.stackexchange.com/questions/5609/how-do-i-clear-bashs-cache-of-paths-to-executables)