macOS 安装 python

来源:互联网 发布:centos 6 搜狗输入法 编辑:程序博客网 时间:2024/05/16 14:12
环境:  macOS Sierra 10.12.1不要用mac系统自带的python, 用brew重新装一个,然后把/usr/local/bin/python指向brew目录下的python.摘自: http://stackoverflow.com/questions/17271319/how-to-install-pip-on-mac-os-xInstalling a separate copy of Python is a popular option, even though Python already comes with MacOS. You take on the responsibility to make sure you're using the copy of Python you intend. But, the benefits are having the latest Python release and some protection from hosing your system if things go badly wrong.To install Python using HomeBrew:```shbrew updatebrew install python # or brew install python3```Now confirm that we're working with our newly installed Python:```shls -lh `which python````...should show a symbolic link to a path with "Cellar" in it like:```shlrwxr-xr-x  1 chris  admin    35B Dec  2 13:40 /usr/local/bin/python -> ../Cellar/python/2.7.8_2/bin/python```**cyper notes: **我没有指到这个目录, 我用`brew switch python x`命令切了一下, 就正常了, 结果如下:```sh?  ~ brew switch python xError: python does not have a version "x" in the Cellar.Versions available: 2.7.12_2?  ~ brew switch python 2.7.12_2Cleaning /usr/local/Cellar/python/2.7.12_239 links created for /usr/local/Cellar/python/2.7.12_2?  ~ ls -lh `which python`lrwxr-xr-x  1 cyper  admin    36B Dec  5 16:31 /usr/local/bin/python -> ../Cellar/python/2.7.12_2/bin/python?  ~```Pip should be installed along with Python. You might want to upgrade it by typing:```pip install --upgrade pip```Now you're ready to install any of the 50,000+ packages on PyPI.### Other NotesFormerly, I've used get-pip.py to install pip. But, the docs warn that get-pip.py does not coordinate with package managers and may leave your system in an inconsistent state. Anyway, there's no need, given that pip is now included with Python as of 2.7.9.Note that pip isn't the only package manager for Python. There's also easy_install. It's no good to mix the two, so don't do it.Finally, if you have both Python 2 and 3 installed, pip will point to whichever Python you installed last. Get in the habit of explicitly using either pip2 or pip3, so you're sure which Python is getting the new library.Happy hacking!
0 0
原创粉丝点击