Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: can't open file 'django-admin.py': [Errno 2] No such file or directory

Tags:

python

django

I have a mac and I am starting to work on django. When I try to make a project on the terminal by writing

python django-admin.py startproject myproject

I get this error

python: can't open file 'django-admin.py': [Errno 2] No such file or directory

While I was looking around for help, one solution suggested to write type django-admin.py to get the location of django-admin.py and use that.

So when I type

python /usr/local/bin/django-admin.py startproject myproject

my project is created.

Can anyone tell my why I need to do this and why I can't write just django-admin.py? Also is there anyway to get around this?

like image 729
ruthless Avatar asked May 28 '14 15:05

ruthless


3 Answers

You're confusing two ways of referring to an executable file.

/usr/local/bin is in your path, and django-admin.py is marked as executable, so you can refer to it without the initial python:

django-admin.py startproject myproject

When you start with python, that is saying "start Python with the script at this path". So, you need to pass the full path, if the script you're trying to start isn't in your current directory.

like image 181
Daniel Roseman Avatar answered Nov 05 '22 11:11

Daniel Roseman


python django-admin.py - Python execute file django-admin.py in the current working directory.

If you add /usr/local/bin into the PATH environment variable, you can just issue django-admin.py instead of python /usr/local/bin/django-admin.py.

  1. Check whether PATH contains /usr/local/bin

    echo $PATH
    
  2. If there's no /usr/local/bin in the variable, add that:

    export PATH=$PATH:/usr/local/bin  # sh, ksh, bash, ..
    
    set path = ($path /usr/local/bin) # csh
    
like image 35
falsetru Avatar answered Nov 05 '22 10:11

falsetru


Use django-admin.py startproject without the python.

You don't need to use python with the django-admin.py startproject, it should work from any directory. Only on windows you need to specify the full path.

django runs the admin script from the python interpreter in your path.

like image 4
Padraic Cunningham Avatar answered Nov 05 '22 11:11

Padraic Cunningham