简体   繁体   English

如何在 Mac OSX 上将 Python 的默认版本设置为 3.x 与 2.7?

[英]How to Set Default Version of Python to 3.x vs 2.7 on Mac OSX?

I am attempting to install django framework using pip install -e django/ , however, it requires Python 3.5+.我正在尝试使用pip install -e django/安装 django 框架,但是,它需要 Python 3.5+。 Mac OSX by default comes with Python 2.7 so I have installed Python 3.6.5 from the python website. Mac OSX 默认附带 Python 2.7,所以我从 python 网站安装了 Python 3.6.5。

I have confirmed the latest version of Python is installed through python3 .我已经确认最新版本的 Python 是通过python3安装的。

I am still unable to install Django likely because Python 2.7 is also installed and seen first by pip.我仍然无法安装 Django,可能是因为 Python 2.7 也已安装并首先被 pip 看到。

Is it necessary to remove Python 2.7 from my system or can I modify PYTHON_HOME to achieve what I would like to do?是否有必要从我的系统中删除 Python 2.7 或者我可以修改PYTHON_HOME来实现我想做的事情?

You can install to python 3 using您可以使用安装到 python 3

pip3 install django

python3 -m pip install django

As abarnert says in the comments, you shouldn't remove the Python 2.7 installation or try to set Python 3 to be the default.正如 abarnert 在评论中所说,您不应该删除 Python 2.7 安装或尝试将 Python 3 设置为默认值。

It's good practice to use a virtual environment.使用虚拟环境是一种很好的做法。 Since you're using Python 3 you could use pipenv .由于您使用的是 Python 3,因此您可以使用pipenv Once the Python 3 virtual environment is activated, python will use the python 3 from the virtual environment.一旦激活了 Python 3 虚拟环境, python将使用虚拟环境中的 Python 3。

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

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