如何在Mac OS X上将Python3设置为默认的Python版本?

时间:2018-04-25 18:01:48

标签: python django python-3.x

我安装了Python 2.7和Python 3.6,我可以输入" python"或" python3"。

但是,当我尝试使用pip install Django==2.0.4安装最新版本的Django时,会检测到Python 2.7,并且可以安装的最高版本是版本1.11,因为Django 2.0.4需要Python3。

总结

我需要在我的机器上使用Python的默认版本为Python3,我不知道如何实现这一点。使用别名不会起作用,因为我试图让其他应用程序检测到正确的版本。我的which python结果应为Python3。

假设答案

我想我需要以比Python 2更喜欢Python3的方式编辑我的Path,但我不确定如何这样做。当我输入echo $PATH时,我得到/anaconda2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin。我不确定这是否有帮助。

有关该怎么做的任何想法?另外,我更喜欢Python3是默认,所以我宁愿不使用virtualenv。

编辑:

开玩笑,没有解决。所以pip3安装了Django2。但是当我运行Django2时,我发现它仍然依赖于Python2.7。这是错误:

File "/anaconda2/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)

 from django.conf.urls import url, include, path
ImportError: cannot import name path

2 个答案:

答案 0 :(得分:0)

按照https://www.maketecheasier.com/using-python-3-on-mac/amp/进行操作,您将得到答案。

答案 1 :(得分:-1)

这取决于操作系统,在windows中你需要添加安装python的目录和你的系统路径,然后你可以更改python.exe文件的名称。 in the python 2 install location python.exe should be called python2.exe and in the python3 install location the file python.exe should remain unchanged.这样你就可以分别从python2和python命令行访问python2或python3。