简体   繁体   English

Python找不到Django

[英]Python can't find Django

I installed Django with the following command in the OSX terminal: 我在OSX终端中使用以下命令安装了Django:

sudo pip install django

but when I check whether python3.4 can find it using the command: 但是当我检查python3.4是否可以使用以下命令找到它时:

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: 但是,如果我使用OSX附带的默认Python2.7并键入:

import django

Then I don't receive any problems. 这样我就不会有任何问题。 How do I make it so python3.4 sees the location of Django? 如何使python3.4看到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? 是添加django的地址是一个更好的选择(我该怎么做?),还是应该尝试在其他地方安装Django? 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. 在终端中执行的命令是什么,以便python3.4可以找到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. 使其更好,以便python3.4知道django的位置,无论它在哪里(我猜是默认的python2.7位置),还是在其他地方安装django。

If you want to install django for python3, you should do: 如果要为python3安装django,则应执行以下操作:

pip3 install django pip3安装Django

If you want to install django for python2, you should do: 如果要为python2安装django,则应执行以下操作:

pip install django. pip安装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 您无法使用随pip一起安装的库在python3上工作,因为python3和python2具有自己的一组环境和路径库

First of all, it's not 首先,不是

import Django

It's, 它的,

import django

Also, make sure you're using the correct version of pip. 另外,请确保您使用的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. 您可能需要指定pip3或pip-3.2(这两个是其中之一,不记得OSX是怎么做到的),因为python 3不是默认的Python版本,除非您使用virtualenv 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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