Problem description
My Mac comes with a version of 2.7.10 Python
but no tools for managing dependencies pip
. When I first started learning, I Python
downloaded the installation script from its official website and installed the 3.6 version Python
. The script automatically configures the environment variables, resulting in pip
reference to the 3.6 version pip3
, I searched the entire hard disk can not find the corresponding version 2.7 pip
.
The awkward part is that there is a Python2
written code in front of me and I can't execute it because I can't install dependencies. I think there is a problem with this development environment and we have to find a way to solve it.
Research
In the online round, saw some netizens warned not to bring their own system to Python
add pip
tools, because of the possibility of causing system anomalies. As to what kind of anomaly I don't want to delve into, I'm concerned that they recommend HomeBrew
managing their own Python
version to maintain the integrity of the system.
Resolve Step 1. Delete by
Python
Official website script installation of python3.6
Since I installed it myself Python
, I need to perform this step. You can skip this step for readers who are not installed.
I have referred Python
to the document's description of the script installation. Please check here. The documentation describes what changes the script will make to the system, and we can restore those changes accordingly. The detailed operation is as follows:
- Delete
/Library/Frameworks/Python.Frameworks
- Delete
/Application/Python 3.6
- Delete the
.bash_profile
path and environment variables exported from the file for Python3.6, and then use the source ./bash_profile
command to make the changes take effect.
Use
HomewBrew
Installation
Python2
And
Python3
Installation methods There are a lot of introductions on the web, and I'm referring to the article "MAC OSX is installing PYTHON 2.7 and PYTHON3" correctly.
However, I did not perform the steps described in this article to modify the order of environment variables. I think this step is superfluous.
After this step, HomeBrew
I managed two versions of Python
2.7.14 and 3.6.4, which have the relevant commands in the /usr/local/bin/
directory. The system also has a self-contained 2.7.10 version, placed in the /usr/bin
directory.
Use method and pros and cons analysis
You Python2
should use commands instead of using them later in the development process python2
python
. Because the commands in my environment python
are the 2.7.10 version of MacOS comes with. While the command is python2
called HomeBrew
managed python2.7.14
, it is in the /usr/local/bin/
directory and is a soft link that is linked to /usr/local/Cellar/python/2.7.14_2/bin/python2
in. command in the same python3
vein. So the development needs to distinguish between the three, which seems a bit awkward.
But I think it python2
python3
's no harm to use and explicitly specify a version, one more character.
It is necessary to maintain the integrity of the system's own Python
environment. On the one hand, not doing so may result in the impact of third-party libraries you use Python
on the system. For example: your own installation pip
tool may appear other libraries that it relies on that you do not provide completely. On the other hand, the system comes with the Python
main service to those for Mac-tailored software, if you make a private change may lead to the future of your installation of software run abnormal.
This approach Python
also benefits when you package your code for publishing. If you are the developer Python
of the application, you can explicitly specify the version for the development work, as long as the user's environment in the packaging or release in place to configure. The resulting package can also be alpha tested in a Mac native Python
environment, because the environment should be consistent with the target user's environment.
This article synchronizes blogs
Managing the Python environment for your Mac