3

I am having a problem with installing Django. It seems that Python will not recognize it once it is installed. Below are the steps I have taken. I'm using Mac OS 10.7.5 Python 2.7 and Django 1.5.1

I am not using virtualenv

What am I doing wrong? Is there any reason Python will not recognize it? How can I fix this?

Here's what I've done:

uninstalled it, (with pip)

Successfully uninstalled Django

checked that is uninstalled (via yolk)

localhost:mysite brendan$ yolk -l
Flask-SQLAlchemy - 0.16         - active 
Flask           - 0.10.1       - active 
Jinja2          - 2.7          - active 
MarkupSafe      - 0.18         - active 
Python          - 2.7          - active development (/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload)
SQLAlchemy      - 0.8.2        - active 
Werkzeug        - 0.9.1        - active 
boto            - 2.9.7        - active 
itsdangerous    - 0.22         - active 
nose            - 1.3.0        - active 
pip             - 1.3.1        - active 
setuptools      - 0.8          - active 
tweepy          - 1.7.1        - non-active 
tweepy          - 1.9          - active 
virtualenv      - 1.9.1        - active 
wsgiref         - 0.1.2        - active development (/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7)
yolk            - 0.4.3        - active 

installed it, (with pip)

localhost:mysite brendan$ pip install django
Downloading/unpacking django
Downloading Django-1.5.1.tar.gz (8.0MB): 8.0MB downloaded
Running setup.py egg_info for package django

warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
Installing collected packages: django
Running setup.py install for django
changing mode of build/scripts-2.7/django-admin.py from 644 to 755

warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
changing mode of /Library/Frameworks/Python.framework/Versions/2.7/bin/django-admin.py to 755
Successfully installed django
Cleaning up...

localhost:mysite brendan$ python
Python 2.7.5 (default, May 19 2013, 13:26:47) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.

And I'm getting this error when trying to import:

>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
>>> 

EDIT / UPDATES:

which pip

/Library/Frameworks/Python.framework/Versions/2.7/bin/pip

which python

/opt/local/bin/python

I am not using virtualenv

10
  • what's the result of which pip and which python? Commented Aug 2, 2013 at 14:08
  • Are you utilizing a virtual environment? Commented Aug 2, 2013 at 14:09
  • 2
    Did you install another python outside of the system python? That isn't the system python path. It is possible that your pip is working with your system python and Django was installed on that Commented Aug 2, 2013 at 14:29
  • @sedavidw It is possible, I dont fully understand Pythonpaths. So my Python 2.7 which is installed in /opt/local/Library should be in /Library ???? Commented Aug 2, 2013 at 14:49
  • 1
    @Deepend, that's not necessarily where it should be, you just need to know which python pip is installing to. This is actually why virtualenv are so helpful. When you make a virtualenv you can specify which python for it to use, and when you install any libraries after that you know they are going to that python without affecting any other python installs. If possible I'd start a virutalenv and that points to your /opt/local/bin/python install and add libraries to that. This is a good ref hackercodex.com/guide/… Commented Aug 2, 2013 at 15:09

3 Answers 3

4

It is likely that your pip installation is pointing to a different python than your python version installed at opt/local/bin/python. It is likely that your pip is talking to the system installed python and not the version you installed.

You can consider uninstalling python and re-installing in the correct path or creating a virtualenv that points to the version of python you desire. Then any subsequent installs will point to the correct version of python without affecting other python installs

Sign up to request clarification or add additional context in comments.

Comments

4

try using pip as the superuser :

sudo pip install -U django

worked for me ...

3 Comments

What about updating pip ? sudo pip install -U pip ? and updating django sudo pip install -U django ?
I have updated pip but it has no effect, I don't believe it is a problem with the instillation of Django but rather where it is being installed or where my Python is that it is not finding it
this worked for me. I still don't get what this does, but without the "-U", i had the import error.
2

The previous answer was correct. The solution does not require reinstall python. Best practice to use virtalenv. On the mac, 'pip' will reference python2 by default, to use python3's pip the command is 'pip3' or 'pip3.4'. In the current virtualenv, use 'pip list' or 'pip3 list' to display all installed modules, if django is not install then 'pip install django'.

1 Comment

hey, can you help me out here. My problem is little off topic. When i do pip3 or pip3.4 it says command not found. Please help me here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.