0

I am new to Django and trying to create my first project. I know that I need to run the command "python django-admin.py startproject iFriends" (iFriends is the folder that I created for the project). Terminal is responding with - "-bash: django-admin.py: command not found." Why is it not working? Is this the wrong command?

I am using Mac OS X 10.7.3, Django 1.4, and Python 2.7.2.

MorrisZ
  • 1
  • 1
  • 2
  • 2
    How have you installed Django? – David Wolever Jun 20 '12 at 04:26
  • in bash type python and in python type import django ... what said? – Mohammad Efazati Jun 20 '12 at 05:11
  • I installed Django from the website, and then I un-tared it by running the command "tar xzvf Django-1.4.tar.gz", then I installed it by commanding "sudo python setup.py install." I'm pretty sure it worked, but when I command import django in python, nothing really happens. – MorrisZ Jun 20 '12 at 19:45
  • 1
    Okay now it's just telling me "/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'django-admin.py': [Errno 2] No such file or directory" – MorrisZ Jun 20 '12 at 19:53

4 Answers4

1

I'm also using Python 2.7 on Mac OS 10.7.x (with Django 1.5.1). I think the tutorial is out of date. Try using "django-admin-2.7.py" command instead of just "django-admin.py," with everything else the same. After more than an hour investigating PATHS and symlinks, etc., this is the solution that worked for me.

Here's the winding road I followed, if you would like to suffer through it for posterity:

  • I found that the Installation Pitfalls article cited earlier was helpful in that it explained in more detail the symlink solution mentioned in the troubleshooting docs (https://docs.djangoproject.com/en/1.5/faq/troubleshooting/#troubleshooting-django-admin-py).
  • However, I couldn't find the django-admin.py file in the normal places suggested.
  • Then, I found the terminal command that will tell you where the files are (also from the django docs, under how to uninstall):

python -c "import sys; sys.path = sys.path[1:]; import django; print(django.path)"

  • Mine returned the following path, very different from the documentation:

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/bin

  • I began to follow the symlink suggestion, but then when I attempted to create a symlink to /usr/local/bin, I couldn't do it (subject for another post).
  • After looking at the $PATH ($ echo $PATH), I thought to look in /opt/local/bin instead of usr/local/bin. And lo-and-behold, there was a file called django-admin-2.7.py. Could it be that I just needed to add the version number to the command in the tutorial?
  • I navigated back to my Code folder where I would put my Django project, and followed the tutorial (https://docs.djangoproject.com/en/1.5/intro/tutorial01/) for setting up a new project. But instead of django-admin.py, I tried django-admin-2.7.py. It worked!
PchopL
  • 11
  • 1
0

Is django-admin.py on your system path? Checkout: https://code.djangoproject.com/wiki/InstallationPitfalls

zaphod
  • 2,045
  • 1
  • 14
  • 18
  • Also, when you run startproject, django will create a iFriends directory under your current directory. So, do not create iFriends manually. – zaphod Jun 20 '12 at 05:04
  • 1
    How do I add django-admin.py to my system path? – MorrisZ Jun 20 '12 at 20:29
0

If you're using windows and needed to update your system path, make sure to close and reopen the command prompt before trying again. I was having a similar problem to you, and this is what fixed it for me.

Fred the Fantastic
  • 1,295
  • 1
  • 9
  • 11
0

As a workaround, run this is Python

import site; site.getsitepackages()

Replace the django-admin with python (your-site-packages-addresss)/django/bin/django-admin.py

Full example for starting project:

python /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/bin/django-admin.py startproject mysite
Punnerud
  • 7,195
  • 2
  • 54
  • 44