Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 978
Josir Avatar asked Aug 11 '20 23:08

Josir


People also ask

What is usr bin python3 bad interpreter no such file or directory?

If your system shows a bad interpreter, no such file or directory is an error message probably it is caused by having a file with different line termination or a carriage return character of an operating system on another operating system.

Where is Virtualenv installed?

If you try to run virtualenv and find it isn't present, you can install it using pip. virtualenv.exe will likely now be found in your python installation directory under the Scripts subdirectory.

What is bad interpreter no such file or directory error?

Each of the systems has its own shells which the system will use to execute its own system scripts. We will consider the bad interpreter no such file or directory errors in diverse operating systems such as Ubuntu, Linux, Mac, and Rosrun. This error does occur in the Unix system, Mac system, and also Microsoft Windows system.

What is a bad interpreter in Python?

Whenever your system displays a bad interpreter on such a file or directory, python is unable to interpret or compile the script for execution. This means the python script contains a carriage that returns the character of a different operating system in the code line.

How to fix Yum not working in Python?

You can find the addressess of the repositories in files that are located within the /etc/yum.repos.d directory. Download these RPM files and install them. If yum still doesn't work, it is possible that Python packages depend on each other and something is still missing.

Do Linux operating systems show Bad interpreter messages?

Note that you can have an error when running a file in your system: If the script path is not directory to the system, and there is the presence of carriage return character of another operating system If the file doesn’t exist or it is deleted. If you are thinking that, do Linux operating systems show bad interpreter messages? Yes! They do.


1 Answers

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.

like image 138
phd Avatar answered Nov 13 '22 11:11

phd