Summarize the pits set by Python3 under MAC in the past few days

The situation at that time: python2 comes with mac,

1. Install python3:

  For the first time, I downloaded the installation package from the official website. The installation directory is under /Library/Frameworks/Python.framework/Versions/3.6/python/..., and the package installed with pip3 is also in this (site-package),

So I uninstalled it, installed it using homebrew, and changed the installation directory to /usr/local/lib

But in any case, the environment variable cannot be generated in /usr/local/bin, no matter if the command is used directly, the reason: the highest sip privilege is not enabled.

  After tossing for a day, I chose to give up, uninstall the natively installed python3, and start all over again

  In order to obtain SIP permissions, it took another day of tossing. Under the wireless keyboard, no matter how you press Command+R, you can enter safe mode. Finally, I built a wired keyboard in the company, entered it at once, and set the permissions with the command csrutil disable.

  Start to reinstall PYTHON3, and the package installed by pip3 also generates environment variables under /usr/local/bin, and the installation problem is finally solved

 

2. Virtual environment

  The originally used virtualenv and its extension vitualenvwrapper, but due to installation problems, no matter how it is used, there is no time to test after the installation problem is solved later.

  Use pipenv instead, and use pipenv install in the directory to create a virtual environment under python2 by default. There is no prompt for this, and I have been tricked again.

Because I didn't know what modules to install after I created the environment, and after running with python3, I reported an error that the module was not found.

  Later, when I went to github to see the specific use of pipenv, I realized that pipenv --two was created with python2, pipenv --three was created with python3, and finally

Solve the problem of virtual environment

 

3. Run the application

  must use sudo

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325172029&siteId=291194637