简体   繁体   English

无法在macOS Sierra上使用Python3导入Django

[英]Can't Import Django using Python3 on macOS Sierra

Have both versions of Python (Legacy 2.7.10 and 3.6.2) installed on macOS Sierra. 在macOS Sierra上安装了两个版本的Python(旧版2.7.10和3.6.2)。

Installed pip using the following steps. 使用以下步骤安装点子。

Downloaded it using curl: 使用curl下载了它:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Installed pip it by running the installer script: 通过运行安装程序脚本来安装pip:

sudo python get-pip.py

Checked for any upgrades / updates for pip: 检查是否有任何升级/更新的点子:

sudo pip install -U pip

Installed django 1.11: 已安装django 1.11:

sudo pip install django==1.11

When I run python (legacy): 当我运行python(旧版)时:

python
Python 2.7.10 (default, Feb  7 2017, 00:08:15) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
1.11

However, when trying it using python3: 但是,使用python3尝试时:

python3
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'django'

Note: I followed a different tutorial and got python3 working with django 1.11 using virtualenv - please don't suggest this as I am new to the python world and just want to use python3 / django 1.11 in a non-virtual environment - I just want have it working like the legacy python interpreter is behaving. 注意:我遵循了不同的教程,并使用virtualenv使python3与django 1.11一起使用-请不要提出这个建议,因为我是python世界的新手,只想在非虚拟环境中使用python3 / django 1.11-我只想使它像旧版python解释器一样工作。

pip installs libraries differently for python2 and python3, so you effectively have different environments for each. pip为python2和python3安装库的方式有所不同,因此每个库实际上都有不同的环境。 If you want to install Django for python3, you'll want to install it like this: 如果要为python3安装Django,则需要这样安装:

pip3 install django==1.11

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

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