QPTR
QPTR

Reputation: 1690

how to solve "bad interpreter: Too many levels of symbolic links"

I am trying to install numpy in a virtual environment that I created. I used the following series of commands to create and activate and then installing a local version of numpy (all these after cd-ing into the project folder).

virtualenv venv
source venv/bin/activate
pip install numpy

However, after the last command, I get this error:

bash: /home/fieldsofgold/Desktop/test/venv/bin/pip: /home/fieldsofgold/Desktop/test/venv/bin/python: bad interpreter: Too many levels of symbolic links

Could anyone please help me solve it and let me know what could be going wrong?

I am using Ubuntu 14.04 in VirtualBox, and the python version is 2.7.6.

Upvotes: 11

Views: 33199

Answers (6)

Ingo
Ingo

Reputation: 26

I had this. In my case I am not sure what happened but my python2 had been replaced by a link so I had:

ls -l
lrwxrwxrwx 1 <me> staff    7 Oct 23 14:04 python -> python2
lrwxrwxrwx 1 <me> staff    6 Nov  6 14:28 python2 -> python
lrwxrwxrwx 1 <me> staff    7 Oct 23 14:04 python2.7 -> python2

The middle link is wrong, this is a circual reference, it should be the executable (had another venv to look at already). I deleted python2 and copied the actual file (in my case /bin/python2.7) to there:

rm python2
cp /bin/python2.7 python2
ls -l
lrwxrwxrwx 1 <me> staff    7 Oct 23 14:04 python -> python2
-rwxr-xr-x 1 <me> staff 7216 Dec  6 14:57 python2
lrwxrwxrwx 1 <me> staff    7 Oct 23 14:04 python2.7 -> python2

(NOTE: I can't speak for every distro. you'll need to work out your own version. Try this:

ls -l `which python`

and if that is a link follow it until you get to the actual executable. For me is was /bin/python -> python2 -> python2.7. Ergo I copied /bin/python2.7)

Upvotes: 0

ShawnZhu
ShawnZhu

Reputation: 69

When I tried to install Tensorflow by Virtualenv, I confronted this question too. I just removed the old env, then built a new env. It works.

When I type which pip, it returns /Users/xiang/tensorflow/bin/pip. Which is exactly the path in the new env I built.

Upvotes: 1

tripleee
tripleee

Reputation: 189628

I can vaguely speculate that the reason for this is that you have a virtualenv pointing to itself. I can further vaguely speculate that this would happen if you attempt to create a virtualenv, but then somehow decide to do it again without running deactivate. Then you have python in the virtualenv pointing back to ... python in (effectively) the same virtualenv by a symbolic link.

Since this is speculative, I hope someone who actually has this problem can confirm or deny that this is what happened.

Anyway, if this is the case, the other answers here saying remove the env and start over are basically correct, but remember to deactivate first.

Upvotes: 0

Mark Francis
Mark Francis

Reputation: 350

I had the same issue, and solved it simply by removing the old env file with rm -rf env. Then I created a new environment with virtualenv env, followed by installing the requirements, normally pip install -r requirements.txt, then I was able to run my app successfully.

Upvotes: 16

Mahipalsaran
Mahipalsaran

Reputation: 81

This error is occurs 'cause time you start a new process, in my case virtual environment for django project one copy is made and when they becomes to many you get this error. Just remove the old env and create a new environment.

Upvotes: 0

Saurabh Kumar
Saurabh Kumar

Reputation: 21

You may have python running in some other instance of terminal. Make sure to close all additional instances of terminals

Upvotes: 1

Related Questions