简体   繁体   中英

Installing Python 2.7 and 3.6 Side by Side on Mac

Python newbie here. I just bought a new Mac Book Pro (switched from Windows) and Python 2.7 is already installed on it. I want to install 3.6 side by side and choose between the two versions. I found a great tutorial located here http://joebergantine.com/articles/installing-python-2-and-python-3-alongside-each-ot/ but I'm confused on one of the command line operations. Under Python 2 Installation it says:

Install Python 2 from the latest Python.org package. This allows you to run python2 and pip. After this installation Python 2.x will be accessible at /Library/Frameworks/Python.framework/Versions/2.7/bin/.

Once the Python 2 package is installed, install virtualenv for Python 2 for the User only. When specifying the User installation, Python packages are then accessible at ~/Library/Python/2.7/bin. Specifying the User installation doesn't automatically add virtualenv to the system path which we will do manually in the next step via an alias. This is what allows Python3 and Python2 to run alongside each other:

$ pip install --user virtualenv

Do I have to be in the ~/Library/Python/2.7/bin directory when I run this command or the /Library/Frameworks/Python.framework/Versions/2.7/bin/ directory? I'm confused because I don't know where the former directory is coming from.

Why not using pip for python 2.7 and pip3 for python 3.6 ?

If it says pip3 is not installed you can use sudo apt-get install pip3

then you can use pip3 for python 3.6 and pip for python2.7 for installing packages for respective versions

I faced the exact error, in the exact situation about 2 years ago. The solution to your issue is pyenv . I was able to run multiple versions of python inside different folders of the same directory. It truly was a very nice solution. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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