繁体   English   中英

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

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

在macOS Sierra上安装了两个版本的Python(旧版2.7.10和3.6.2)。

使用以下步骤安装点子。

使用curl下载了它:

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

通过运行安装程序脚本来安装pip:

sudo python get-pip.py

检查是否有任何升级/更新的点子:

sudo pip install -U pip

已安装django 1.11:

sudo pip install django==1.11

当我运行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

但是,使用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'

注意:我遵循了不同的教程,并使用virtualenv使python3与django 1.11一起使用-请不要提出这个建议,因为我是python世界的新手,只想在非虚拟环境中使用python3 / django 1.11-我只想使它像旧版python解释器一样工作。

pip为python2和python3安装库的方式有所不同,因此每个库实际上都有不同的环境。 如果要为python3安装Django,则需要这样安装:

pip3 install django==1.11

暂无
暂无

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

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