32
votes

I am a complete beginner to Python/Django, but I want to dive right in and start experimenting. Thus I was following this guide on installing Python/Django http://devcenter.heroku.com/articles/django.

Everything is working fine until the step

django-admin.py startproject hellodjango

Where I get

command not found: django-admin.py

Now I have tried a few things, but none have really worked out. Is there someone kind enough to point me in the right direction?

P.S. Is there a great guide out there on running Python/Django locally on a Mac to run and test apps?

I'm on Mac OS X Lion, Python 2.7.

28
You need to give more details. What have you tried? It sounds like django isn't installed or not on your python path. You should look into running your django apps with virtualenv which will give you an encapsulated enviroment in which to install django etc. - Timmy O'Mahony
@pastylegs: That guide does suggest using virtualenv. - Paul McMillan
Have you tried the official Django tutorial guide? - Dirk
@pastylegs yes, the guide suggests using virtualenv, up to that step I had no problems. However I acknowledge the fact that I may be missing something really basic here (the guide was followed very closely though). - Simon
Looks like I had to reinstall Django on a global basis to make this work. - Simon

28 Answers

26
votes

Actually, if you use Ubuntu, it's just django-admin not django-admin.py.

Resides in /usr/bin
Probably the same thing on Mac.
You're using a Windows tutorial.

It may also tell you

python manage.py runserver

and that is actually

python ./manage.py runserver
25
votes

When that didn't work for me, I tried python -m django startproject mysite and it worked.

10
votes

Make sure you properly did the source bin/activate command. If you skip that, or do it in a different terminal window, or close the window then re-open it, you won't be in the virtualenv and you won't have access to the django-admin.py command in your environment.

7
votes

To solve this problem, you need:

  1. Find the main folder of Django, and find the django-admin.py file

    Typically, the file is in <YOUR_DJANGO_FOLDER>/bin/django-admin.py

  2. Create a link for this file

    ln -s /bin/django-admin.py /usr/local/bin/django-admin

  3. Type django-admin in your command to check if it works

6
votes

I tried as the method, it worked.

pip uninstall django
sudo pip install django
django-admin startproject example

It worked well.

5
votes

If you´re on Windows, here´s what worked for me (using pylauncher):

$ py -m django startproject myproject
4
votes

As Timmy said above, it could just be that django-admin.py is not on your system path. See here - https://code.djangoproject.com/wiki/InstallationPitfalls - for 3 possible causes with solutions.

3
votes

I have used follwong command to install (/usr/local/bin) MAC OS

pip install django

django-admin startproject mysite
3
votes

To Windows users

using django-admin instead of django-admin.py worked for me in Windows.

enter image description here

3
votes

For me this one worked

python3 -m django startproject mysite

Then it doesn't tell you that it created file you must check by yourself in your home

hardrive/user/urhome
2
votes

The following guide in official site https://code.djangoproject.com/wiki/InstallationPitfalls

First, you should find location of django-admin.py by

which django-admin.py

Example: in my case

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/bin/django-admin.py

You use sudo ln -s to relocate django-admin-py to /usr/local/bin

sudo ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/bin/django-admin.py /usr/local/bin/django-admin.py

after that change permission of the django-admin to be executable sudo chmod +x /usr/local/bin/django-admin.py

Now you can use django-admin.py startproject mysite to create your django project


If you want to change django-admin.py to django-admin to look like more compact you can use sudo mv /usr/local/bin/django-admin.py /usr/local/bin/django-admin

Hope this help for you !

2
votes
python3 -m django startproject mango
2
votes

I was just having the same problem, I just did an upgrade and that's it, it worked, I hope this is useful for future problems in Linux:

pip install --upgrade django
1
votes

To windows users out there: I have faced this problem several times and here are the checkpoints:

When there is problem initiating a new project, make sure:

1) python is working in the command line (type in python and see if you get the console)

2) specify the full path of django-admin.py in the command

3) check django-admin.py is in the system path

4) cd the command line path to where you want the new project

Screenshot of what finally worked for me (only the last command): https://flic.kr/p/r9LJ67 (stackoverflow doesn't allow me to post pictures yet)

1
votes

If you come across command not found: django-admin.py problem which means you don't installed django frame work. You should install the framework using pip.

pip install django

After that look at the directory if the related script exist or not.
Look into C:\Python27\Scriptsfolder to check for django-admin.py exist or not.

1
votes

if you install django by pip

  • ensure you have installed django:

pip list or pip freeze

if there is django then

  • get location of django:

pip show django

if location is '/Users/xxxxx/Library/Python/2.7/lib/python/site-packages' then

  • relocate django-admin-py to /usr/local/bin:

ln -s /Users/xxxxx/Library/Python/2.7/lib/python/site-packages/django/bin/django-admin.py /usr/local/bin/django-admin.py

1
votes

This simply worked for me. Install django on your virtualenv:

pip install django

And then run:

django-admin startproject myprojectname
1
votes

Get site-package path with Python:

import site; site.getsitepackages()

And run django-admin.py directly:

python (your-site-package-addresss)/django/bin/django-admin.py startproject hellodjango



On Mac: If this works you can go and add django-admin.py to your path using symlink:

sudo ln -s (your-site-package-addresss)/django/bin/django-admin.py /usr/local/bin/django-admin

(could be that you have to reopen terminal or reinstall django to get the symlink working)

1
votes

I changed my complete python path to desktop and tried and it's working well for me

0
votes

On RHEL stock python config:

django-admin.py startproject mysite

0
votes

I'm running macOS and I'm using pyenv instead of virtualenv. I'm not sure if they behave similarly, but I was having the same problem in which django-admin.py was not found.

After a while I've noticed that I had a warning after installing django: pyenv: cannot rehash: /Users/msvolenski/.pyenv/shims/.pyenv-shim exists

Once I deleted this file and ran pyenv rehash it all started working perfectly.

Hope this helps!

0
votes

For Windows Users first search for django-admin, right click on the file that has been found and open file location and keep it open.

Using Windows Powershell, cd into the the folder where you want to create your django project

when your in the right folder write the full path of where django-admin is located in my case I am using Anaconda 3 so the file location is

C:\Users\Sen\Anaconda3\Scripts

so in Windows PowerShell type C:\Users\Sen\Anaconda3\Scripts\django-admin.py startproject [name of project]

hope this helps!

0
votes

I had the same issue when migrating to AWS Beanstalk it was installed and everything but i noticed the alias was not working but when i called the entire thing path and all it worked so i just rebooted the boxes and it worked i think the alias list is not updated automatically after you install.

0
votes

It has to do with the PATH:

Put this in the .bash_profiel and the source it (for mac users only): (change the location with the location of your installed python libraries)

PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
0
votes

If someone is facing the same problem, and is on MacOs, here is what I did, and it worked for me:

If you've installed python directly from the official website, uninstall it, and install it once again using brew:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

$ brew install python3

This will also install the pip3 for you, so you don't have to install it by yourself.

0
votes

I was facing the same issue.

The issue resolved after I upgraded the django version using

pip install --upgrade django

Then run

django-admin startproject mysite

Hope this helps!

0
votes

There was a space in one of the names in the path to my project. I set up a new virtual environment in a new directory and did all the same things and it works.

Sometimes it is the simple things...

0
votes

There may be a chance that your path is not correct. Ubuntu has a .local/bin folder which pip uses to install module binaries and you need it in your path to use django or any shell commands installed using pip.

  • Open ~/.bashrc or ~/.zshrc
  • Add the following line and save it
export PATH="/home/animesh/.local/bin:$PATH"
  • restart the shell with source ~/.zshrc