无法在macOS Sierra上使用Python3导入Django [英] Can't Import Django using Python3 on macOS Sierra

查看:57
本文介绍了无法在macOS Sierra上使用Python3导入Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Have both versions of Python (Legacy 2.7.10 and 3.6.2) installed on macOS Sierra.

按照以下步骤安装点子.

Installed pip using the following steps.

使用curl下载它:

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

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

Installed pip it by running the installer script:

sudo python get-pip.py

检查了pip的任何升级/更新:

Checked for any upgrades / updates for pip:

sudo pip install -U pip

已安装django 1.11:

Installed django 1.11:

sudo pip install django==1.11

当我运行python(旧版)时:

When I run python (legacy):

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尝试时:

However, when trying it using 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解释器一样工作.

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.

推荐答案

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

pip installs libraries differently for python2 and python3, so you effectively have different environments for each. If you want to install Django for python3, you'll want to install it like this:

pip3 install django == 1.11

这篇关于无法在macOS Sierra上使用Python3导入Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆