0

I installed django using pip, however typing import django in the python console yields the following error:

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

When I run pip install django I get the following:

Requirement already satisfied (use --upgrade to upgrade): django in /usr/local/lib/python2.7/site-packages
Cleaning up...

However running which python in the terminal yields the following:

/usr/bin/python

I am wondering whether django does not import because a version I installed using homebrew conflicts with the mac pre-installed version.

I should mention that i am able to import django in the console when in the directory /usr/local/lib/python2.7/site-packages

Any help is appreciated.

i_trope
  • 1,554
  • 2
  • 22
  • 42

2 Answers2

1

You should import django, not Django, watch the case.

Demo:

$ pip install django
Requirement already satisfied (use --upgrade to upgrade): django in ...
Cleaning up...
$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named Django
>>> import django
>>>
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • I re-ran pip install django and have the same issue. In addition, import django works as in your demo, but only when in /usr/local/lib/python2.7/site-packages – i_trope Mar 27 '14 at 19:05
  • @user2475612 that's a different problem now. Looks like it's a `PYTHONPATH` problem, see http://stackoverflow.com/questions/9462212/import-error-no-module-named-django – alecxe Mar 27 '14 at 19:09
0

I couldn't fix the $PATH conflict between my OSX default version (2.7.10) and my pip installed one (3.8). Instead, I manually specify the entire path when calling django-admin:

Go to your project folder in console and type (check your version first).

your_proyect_folder$ python3 /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/bin/django-admin.py startproject your_folder_name
crimsonpython24
  • 2,223
  • 2
  • 11
  • 27