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


Question

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?

1
5
9/15/2011 4:45:40 PM

Accepted Answer

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/.

20
10/9/2017 3:03:46 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon