Josir
Josir

Reputation: 1644

How to fix /usr/local/bin/virtualenv: /usr/bin/python: bad interpreter: No such file or directory?

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.

Upvotes: 7

Views: 9454

Answers (2)

phd
phd

Reputation: 94453

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.

Upvotes: 4

Jessy Guirado
Jessy Guirado

Reputation: 228

Installing via debian packages created me errors in the past. The solution to your problem is using pip:

sudo pip3 install virtualenv

Full tutorial here: How to install virtualenv for Python3 on Linux

Upvotes: -2

Related Questions