Issue
When I tried to use virtualenv on Ubuntu 18.04, I got this error:
bash: /usr/local/bin/virtualenv: /usr/bin/python: bad interpreter: No such file or directory
Python 2 and 3 is working fine:
josir@desenv16:~/bin$ which python3
/usr/bin/python3
josir@desenv16:~/bin$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
I've already tried to unistall virtualenv:
sudo apt-get purge --auto-remove virtualenv
sudo apt-get purge --auto-remove python-virtualenv
sudo apt-get purge --auto-remove python3-virtualenv
But when I installed again, the error remains.
Solution
bash: /usr/local/bin/virtualenv: /usr/bin/python: bad interpreter: No such file or directory
The error is in '/usr/local/bin/virtualenv' — it's first line (shebang) is #!/usr/bin/python
and there is no such file at your system.
I believe the stream of events led to the situation is: you've installed virtualenv
with pip
(not apt
) long ago and put /usr/local/bin
at the front of your $PATH
. Then you upgraded you system; the upgrade removed /usr/bin/python
, now you have only /usr/bin/python3
.
Now you have to decide which route you'd go: apt
or pip
. If you choose apt
— remove /usr/local/bin/virtualenv
.
If you choose pip
: my advice is to uninstall as much as possible python packages installed with apt
; reinstall virtualenv
; that should be the only additional package installed with apt
. For every project/task create a virtual environment and install packages with pip
.
PS. Personal experience: I switched from apt
way to pip
a few years ago.
PPS. Avoid using sudo pip
— do not clobber system installation. Either install into virtual environments or pip install --user
.
Answered By - phd