0

When I type ipython notebook it works fine. However I need to work into a virtual environment:

What I do

virtualenv .env
source .env/bin/activate
pip install -r requirements.txt

Now I type

ipython notebook

This given the error:

/home/derk/assignment2/.env/bin/python: bad interpreter: No such file or directory

So when not in the virtual environment I can start the notebook. However, when not into the virtual environment it gives an error.

The requirements.txt looks like this:

Cython==0.21.2
Jinja2==2.7.3
MarkupSafe==0.23
Pillow==2.7.0
backports.ssl-match-hostname==3.4.0.2
certifi==14.05.14
gnureadline==6.3.3
ipython==2.3.1
matplotlib==1.4.2
mock==1.0.1
nose==1.3.4
numpy==1.9.1
pyparsing==2.0.3
python-dateutil==2.4.0
pytz==2014.10
pyzmq==14.4.1
scipy==0.14.1
six==1.9.0
tornado==4.0.2
wsgiref==0.1.2

Everything worked correctly before, but now (maybe after some software updates) it doesnot. I tried reinstalling Anaconda (as suggested on some sites), but without success. What could be the problem here?

Derk
  • 1,385
  • 3
  • 19
  • 38
  • what is the output of `ls -l /home/derk/assignment2/.env/bin/python`? – cel Nov 01 '15 at 15:31
  • Output: -rwxrwxr-x 1 derk derk 3345416 nov 1 15:47 /home/derk/cs231n/assignment2/.env/bin/python – Derk Nov 01 '15 at 15:40
  • I notice now I moved the notebooks to another folder /home/derk/cs231n/assignment2 instead of /home/derk/assignment2. Why is it now going wrong? – Derk Nov 01 '15 at 15:45
  • You cannot simply move a virtualenv. Instead create a new one at the desired location and delete the old one. – cel Nov 01 '15 at 15:46

1 Answers1

0

This error can happen when one has moved or renamed the virtualenv. In my case, the folder was moved to another user(mint -> emil), but otherwise had the same path. To solve it one can edit the configuration files, see this answer. In my case, python worked fine within the virtualenv, but ipython did not:

(env) emil@emil-VirtualBox ~/X/X $ ipython
bash: /home/emil/X/env/bin/ipython: /home/mint/X/env/bin/python3.5: bad interpreter: No such file or directory

Checking which file was run:

(env) emil@emil-VirtualBox ~/X/env/bin $ which ipython
/home/emil/X/env/bin/ipython

Did not indicate a problem. I browsed into the folder and the file was there. So it wasn't missing. Then I remembered that I had had to edit some files after moving the virtualenv earlier. One has to edit the 'bash header' (sha-bang) in all the important files. In my case, these were:

activate
pip
ipython

I.e., find the header which looks like:

#!/home/mint/X/env/bin/python3.5

and change to:

#!/home/emil/X/env/bin/python3.5
Community
  • 1
  • 1
CoderGuy123
  • 6,219
  • 5
  • 59
  • 89