Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: "bad interpreter: No such file or directory" when running django-admin.py

Tags:

python

django

I've googled the hell out of this, but all of the solutions I've found seem to solve problems that are not mine.

I created a project in a virtual environment in /Users/[user]/Documents/projects/[project] using virtualenv and installed Django.

Later, I deleted that project and installed Django on my system outside of the virtual environment. Now, I am trying to run this:

django-admin.py startproject mysite

However, I am receiving this error message:

-bash: /usr/local/bin/django-admin.py: 
/Users/[user]/Documents/projects/[project]/bin/python:
bad interpreter: No such file or directory

I have found that the only way I can make this work again is by setting up the [project] virtual environment as I had it before with Django installed in it.

How do I fix this?

like image 602
Corey Avatar asked Sep 15 '11 16:09

Corey


1 Answers

I'm not sure what you did to produce this error, but the fix for you is to change /usr/local/bin/django-admin.py shebang to #!/usr/bin/env python.


Actually if you install django in a virtualenv, the django-admin.py will have the shebang set to the python interpreter of your virtualenv, but this script will not be created in /usr/local/bin/.

Instead this script will be created in /<virtualenvpath>/bin/ along with activate and the virtualenv python interpreter. You should then move this script to /usr/local/bin/.

like image 97
mouad Avatar answered Sep 21 '22 06:09

mouad