Reputation: 2793
OS : OS X 10.7.5 I have pyhton 3.3.2 installed under Apps folder and I use IDLE for python scripts. I used below command to install Django.
pip install Django==1.5.2
After successful installation I see it installed under ~/Library/Python/2.7/site-packages/
However when I use IDLE to test
import django
I get below error:
>>> import django
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import django
ImportError: No module named 'django'
What am I missing ? This is the first time I am trying django installation.
As per suggestion, I installed virtualenv and tried
sudo virtualenv -p /Library/Frameworks/Python.framework/Versions/3.3/ my_virtualenv
It failed with below trace:
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.3/
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 8, in <module>
load_entry_point('virtualenv==1.10.1', 'console_scripts', 'virtualenv')()
File "/Library/Python/2.7/site-packages/virtualenv.py", line 780, in main
popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1202, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
Seems like still its trying to install under 2.7 version.
Upvotes: 3
Views: 4387
Reputation: 2793
Here are the steps that resolved my issue:
Removed Python 3.3 completely from machine.
sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.3
sudo rm -rf "/Applications/Python 3.3"
cd /usr/local/bin;
ls -l . | grep '../Library/Frameworks/Python.framework/Versions/3.3' | awk '{print $9}' | xargs rm
And then setup the environment using guide to set Up Python and Install Django on Mac OS X.
Upvotes: 0
Reputation: 2523
You have a conflict between python 2.7 and 3.3.2. You installed django for python 2.7 and certainly tried to used it with python 3.3.2.
The best way to avoid this kind of problem is to use virtualenv:
$ sudo pip install virtualenv
Then:
$ virtualenv my_virtualenv
OR:
$ virtualenv -p <PATH TO PYTHON VERSION> my_virtualenv
Then:
$ source my_virtualenv/bin/activate
$ pip install Django==1.5.2
This will install the good version of django in your virtualenv. You need to check if the python 3 version is available with pip.
Thanks to virtualanv, you will be able to save/freeze and install your environement on another machine:
$ pip freeze > requirement.txt
$ pip install -r requirement.txt
Upvotes: 5