django-admin command not working in Mac OS

Question:

I started Django in Mac OS and after installing Django using pip, I tried to initiated a new project using the command django-admin startproject mysite. I get the error -bash: django-admin: command not found. I make quick search in Google and haven’t get any solution that works.

How to start a new project using Django using django-admin ?

Asked By: Arefe

||

Answers:

Try the following:

django-admin.py startproject mysite
Answered By: Daniel Mouris

I solved the issue after reading a webpage about the mentioned issue.

  1. In the Python shell, write the following,

    >> import django
    >> django.__file__
    >> django also works

It will provide the installation location of django.

  1. Change the path to the new path /usr/local/bin/django-admin.py,

    sudo ln -s the complete path of django-admin.py /usr/local/bin/django-admin.py

In Mac OS, The call needs to be django-admin.py startproject mysite than django-admin startproject mysite

Answered By: Arefe

You need to add django to your path variables and then restart the terminal.

Answered By: sprksh

I know I’m jumping in a little late, but my installations seem to all reside away from /usr/local/bin/… . What worked for me was adding an export path in bash_profile for my django installation.

This also made me realize that it was installed globally. From what I’ve heard, it’s better to install django locally within venv as you work on different projects. That way each virtual environment can contain its own versions and dependencies for django (and whatever else you’re using). Big thanks to @Arefe.

Answered By: wookie4hire

First install Django, lets assume you have python3.7 and want to install django 2.0.3, in this case using pip3.7 to install

sudo pip3.7 install django==2.0.3

now try to see if django-admin.py is installed using

ls /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/bin

If you see django-admin.py just link it to the /usr/local/bin using this command

ln -s /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/bin /usr/local/bin/

Then you could run this command to create new python project

django-admin startproject mysite
Answered By: Hussein Alrubaye
pip install django 

after

django-admin startproject nameProject
Answered By: Oleg

On mac, try to uninstall it via python -m pip uninstall Django, then you get the actual path to django-admin, then you can do chmod +x /Users/pano/.pyenv/versions/3.9.5/bin/django-admin

$ python -m pip uninstall Django
Found existing installation: Django 4.0.6
Uninstalling Django-4.0.6:
  Would remove:
    /Users/pano/.pyenv/versions/3.9.5/bin/django-admin
    /Users/pano/.pyenv/versions/3.9.5/lib/python3.9/site-packages/Django-4.0.6.dist-info/*
Proceed (Y/n)? Y
  Successfully uninstalled Django-4.0.6

Answered By: heypano

try this. this should work for you with no problem.

pip3 install django

python3 -m django startproject PROJECTNAME

you can use python and pip command without mentioning 3 either.

Answered By: R00t761

In my case, i was forgot to activate the virtual environment.

pipenv shell
Answered By: Jasbir Rana
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.