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 .
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.
730 Answers
When that didn't work for me, I tried python -m django startproject mysite and it worked.
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 1I tried as the method, it worked.
pip uninstall django sudo pip install django django-admin startproject example It worked well.
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.
To solve this problem, you need:
Find the main folder of Django, and find the
django-admin.pyfileTypically, the file is in
<YOUR_DJANGO_FOLDER>/bin/django-admin.pyCreate a link for this file
ln -s /bin/django-admin.py /usr/local/bin/django-admin
Type
django-adminin your command to check if it works
If you´re on Windows, here´s what worked for me (using pylauncher):
$ py -m django startproject myproject As Timmy said above, it could just be that django-admin.py is not on your system path. See here - - for 3 possible causes with solutions.
0To Windows users
using django-admin instead of django-admin.py worked for me in Windows.
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 1python3 -m django startproject mango I have used follwong command to install (/usr/local/bin) MAC OS
pip install django django-admin startproject mysite The following guide in official site
First, you should find location of django-admin.py by
which django-admin.py Example: in my case
/Library/Frameworks/
You use sudo ln -s to relocate django-admin-py to /usr/local/bin
sudo ln -s /Library/Frameworks/ /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 !
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 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): (stackoverflow doesn't allow me to post pictures yet)
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.
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
This simply worked for me. Install django on your virtualenv:
pip install django And then run:
django-admin startproject myprojectname 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)
I changed my complete python path to desktop and tried and it's working well for me
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
~/.bashrcor~/.zshrc - Add the following line and save it
export PATH="/home/animesh/.local/bin:$PATH" - restart the shell with
source ~/.zshrc
On RHEL stock python config:
django-admin.py startproject mysite
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!
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!
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.
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/" export PATH 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 )" $ brew install python3 This will also install the pip3 for you, so you don't have to install it by yourself.
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!
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...
1In my case i simply forgot to run pip install django
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:
- cd [your project path]
virtualenv venv
- you can active your environment by :
source ./venv/bin/active
- 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
- to run your python script use :
python <.py file>
and if you didn't activate your env use :
./venv/bin/python <.py file>
