[Django]-Command not found: django-admin.py

70πŸ‘

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

38πŸ‘

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

22πŸ‘

I tried as the method, it worked.

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

It worked well.

πŸ‘€Marc Steven

13πŸ‘

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.

πŸ‘€Paul McMillan

13πŸ‘

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

$ py -m django startproject myproject
πŸ‘€Heron Rossi

8πŸ‘

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

πŸ‘€ZwEin

5πŸ‘

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
πŸ‘€user12247270

4πŸ‘

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.

πŸ‘€jacanterbury

4πŸ‘

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

pip install django

django-admin startproject mysite
πŸ‘€Vinod Joshi

4πŸ‘

To Windows users

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

enter image description here

4πŸ‘

python3 -m django startproject mango
πŸ‘€fullmoon

2πŸ‘

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 !

πŸ‘€Giang

2πŸ‘

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

pip install django

And then run:

django-admin startproject myprojectname
πŸ‘€sptramp

2πŸ‘

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
πŸ‘€Jon Quino

2πŸ‘

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
πŸ‘€era5tone

1πŸ‘

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)

πŸ‘€Vicky Zhang

1πŸ‘

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.

πŸ‘€Harun ERGUL

1πŸ‘

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

πŸ‘€zhangliang

1πŸ‘

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)

πŸ‘€Punnerud

1πŸ‘

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

πŸ‘€I.SRI RAM

1πŸ‘

In my case i simply forgot to run pip install django

πŸ‘€Eric

0πŸ‘

On RHEL stock python config:

django-admin.py startproject mysite

πŸ‘€Roy Holzem

0πŸ‘

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πŸ‘

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!

πŸ‘€Seenvp

0πŸ‘

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.

πŸ‘€sgora

0πŸ‘

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πŸ‘

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.

πŸ‘€yosra

0πŸ‘

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!

πŸ‘€ANIKET PATIL

0πŸ‘

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πŸ‘

Since you’re just starting out. It is very important to adopt best practices. You will face many dependency related issues with this approach of development. In this case it is always recommended to work with a virtual environment for each python project.

This will ensure fresh installation of project-specific dependencies that do not overlap with what the system you are running on already has.

If you have not already noticed, you will come across more issues such as python3 not working with earlier versions of django. pip will skip install as it checks and finds a version of django already installed. So this cannot be stressed enough, always use a virtual environment for local setups.

to do so:

  1. cd [your project path]

virtualenv venv

  1. you can active your environment by :

source ./venv/bin/active

  1. install your requirements packages with pip :

pip install -r
or pip install
you can also install your requirements modules without activate the environment

./venv/bin/pip install

  1. to run your python script use :

python <.py file>

and if you didn’t activate your env use :

./venv/bin/python <.py file>

πŸ‘€Adhin Neupane

0πŸ‘

I take as reference this page and it tells you what to do very clearly.

https://realpython.com/django-setup/

Here are the steps in short if you don’t want to visit the site.

  1. Set up a virtual environment in a folder that you created. I created in Desktop a folder named "python_project". Inside that folder run: python3 -m venv env in terminal.

  2. Then activate the virtual environment with command: source env/bin/activate

  3. Install django after activating virtual environment with this command: python -m pip install django

  4. Pin your dependencies to make sure that you’re keeping track of which Django version you installed: python -m pip freeze > requirements.txt

  5. Start a django project django-admin startproject

  6. Then start a django app which should be inside first folder of the project so first change directory to then in terminal enter this command: python manage.py startapp

Then most probably you will see a scaffolding like this:

setup/
β”‚
β”œβ”€β”€ example/
β”‚   β”‚
β”‚   β”œβ”€β”€ migrations/
β”‚   β”‚   └── __init__.py
β”‚   β”‚
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ admin.py
β”‚   β”œβ”€β”€ apps.py
β”‚   β”œβ”€β”€ models.py
β”‚   β”œβ”€β”€ tests.py
β”‚   └── views.py
β”‚
β”œβ”€β”€ setup/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ asgi.py
β”‚   β”œβ”€β”€ settings.py
β”‚   β”œβ”€β”€ urls.py
β”‚   └── wsgi.py
β”‚
└── manage.py
πŸ‘€Muhittin Kaya

Leave a comment