[Django]-Zsh: command not found: django-admin when starting a django project

10πŸ‘

βœ…

I found an alternative solution.
With find / -name django-admin I found django-admin in myHome/.local/bin/django-admin.

So instead of django-admin startproject mysite I use the full path myHome/.local/bin/django-admin startproject mysite

thanks to @Evert, this is why I got the problem.
his comment:

This is likely because you either used the --user option to pip 
install, or you set up pip in such a way that it automatically does 
that. Hence, everything gets installed in $HOME/.local. You may want
to add $HOME/.local/bin to your $PATH for the future.
πŸ‘€BoumTAC

12πŸ‘

I faced a similar issue on Mac OS but I moved in another way. I used Virtual Environments.

First, create the virtual environment

python3 -m venv django-env

Then, use this environment

source django-env/bin/activate

Next, install django

python -m pip install django

Finally test django is working

django-admin startproject mysite

In my opinion, it is better to have environments isolated to avoid O.S. settings

πŸ‘€Juan Cabello

9πŸ‘

When I had the problem on my mac I just uninstall django and install it again but with root permissions. Now it’s working good)

pip3 uninstall django

sudo pip3 install django 
πŸ‘€Tymophiyy

1πŸ‘

I was facing the same problem after updating my Mac OS to Catalina, and shell from bash to zsh.
None of the commands would work, as if all my paths were deleted.

Looking at Brady Huang’s answer, doing something similar worked for me.

I made sure django was installed correctly by reinstalling it

pip3 uninstall django
pip3 install django 

I found django installed under:

/Library/Frameworks/Python.framework/Versions/3.8/bin/django-admin

by running:

sudo ln -s /Library/Frameworks/Python.framework/Versions/3.8/bin/django-admin usr/local/bin 

I was able to run django-admin again.

0πŸ‘

My adjango-admin is located in

~/Library/Python/3.7/bin/django-admin

But I don’t have it in my linked PATH which is looks like this

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin

So I create a symlink to one of the bin I have in my PATH

sudo ln -s ~/Library/Python/3.7/bin/django-admin /usr/local/bin

It solves my issue

πŸ‘€Brady Huang

0πŸ‘

You may be having some dependency issues.

So to avoid it happen again you need to create a virtual environment only for the current project you are doing. Like this you can avoid having issues and isolate your application.

You can follow this question to create a virtual environment and add django in it.

Then, as soon as you create the virtual environment and activated you can pip install django and check to see whether it is installed.

πŸ‘€Elias Prado

0πŸ‘

Tried many stuffs but then installing the python version 3.11 and using a virtual env solved the issue. Earlier I was using 3.8.9. Hope this helps someone

0πŸ‘

what worked for me!

  1. I just Added the following in my ~/.zshrc file( you can also add it in the ~/.bashrc file if you are not using zsh terminal)

     export PATH=$PATH:$HOME/.local/bin
    

This solution will work not only for you django-admin command but all other python package commands that would behave in a similar way.

πŸ‘€Mr Coolman

Leave a comment