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 ?
Answers:
Try the following:
django-admin.py startproject mysite
I solved the issue after reading a webpage about the mentioned issue.
-
In the Python shell, write the following,
>> import django
>> django.__file__
>> django also works
It will provide the installation location of django.
-
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
You need to add django to your path variables and then restart the terminal.
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.
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
pip install django
after
django-admin startproject nameProject
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
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.
In my case, i was forgot to activate the virtual environment.
pipenv shell
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 ?
Try the following:
django-admin.py startproject mysite
I solved the issue after reading a webpage about the mentioned issue.
-
In the Python shell, write the following,
>> import django
>> django.__file__
>> django also works
It will provide the installation location of django.
-
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
You need to add django to your path variables and then restart the terminal.
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.
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
pip install django
after
django-admin startproject nameProject
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
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.
In my case, i was forgot to activate the virtual environment.
pipenv shell