How do I install the pip package for python on mac

2019-07-24 22:34发布

I'm currently stuck on exercise 46 in Zed Shaw's "Learn Python the Hardway". He says I need to install the following python packages:

  1. pip
  2. distribute
  3. nose
  4. virtualenv

He doesn't give the reader any directions on how to properly install the packages and use them. I went to the pip website but the directions were also very vague and kind of unhelpful for a newbie. The installation guide found on https://pip.pypa.io/en/latest/installing.html says to download the get-pip.py file and then run it by typing python get-pip.py in what I presume to be terminal.

When I do that it starts downloading, then says cleaning up.. and then a red error message appears that says:

Exception:
Traceback (most recent call last):" 

followed by a bunch of file names before ending with 

"OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip

Does anyone know how to correct this? If it helps, the get-pip.py file is in my downloads folder, so I did cd Downloads before running python get-pip.py"

2条回答
ゆ 、 Hurt°
2楼-- · 2019-07-24 23:03

You can do:

sudo easy_install pip

or install it with homebrew: http://mxcl.github.io/homebrew/

and then:

brew install python
查看更多
Animai°情兽
3楼-- · 2019-07-24 23:11

The error-message is IMHO pretty clear - you are not allowed to write into the given directory.

The reason for this is that you use the system-provided Python 2.7. While installing pip shouldn't break it, I personally would rather download a Python 2.7 installer, install it, and then do

$ /Library/Frameworks/Python.framework/Versions/2.7/bin/python get-pip.py

This should install pip into this python, and place the pip-executable at the same location as just given

$ /Library/Frameworks/Python.framework/Versions/2.7/bin/pip

If you insist on using the system python, make it "sudo python get-pip.py". But I wouldn't mess with my system python unless forced to.

查看更多
登录 后发表回答