简体   繁体   中英

Python can't find Django

I installed Django with the following command in the OSX terminal:

sudo pip install django

but when I check whether python3.4 can find it using the command:

import django

I get an error saying it can't find it. However if I use the default Python2.7 that comes with OSX and type:

import django

Then I don't receive any problems. How do I make it so python3.4 sees the location of Django? Is adding the address of where django is a better choice(how do I do this?) or should I had tried to install Django somewhere else instead? If so where and again how do I do specify the location through the command?

Basically I want to know:

  1. What is the command in the terminal to make it so python3.4 can find django.

  2. Is it better to make it so python3.4 knows the location of django, wherever it is (default python2.7 location I guess?) or to install django elsewhere.

If you want to install django for python3, you should do:

pip3 install django

If you want to install django for python2, you should do:

pip install django.

You can not use library installed with pip to works on python3 because python3 and python2 have their own set of environment and path library

First of all, it's not

import Django

It's,

import django

Also, make sure you're using the correct version of pip. You'll probably need to specify pip3 or pip-3.2 (one of the two, can't remember how OSX does it off the top of my head), since python 3 is not the default Python version, unless you're using virtualenv.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM