简体   繁体   English

如何在OS X上安装Python 2.6的pip?

[英]How do I install pip for Python 2.6 on OS X?

I have an OS X system where I need to install a module for python 2.6. 我有一个OS X系统,我需要为python 2.6安装一个模块。 Both pip and easy_install-2.6 are failing: pipeasy_install-2.6都失败了:

# /usr/bin/easy_install-2.6 pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Download error: unknown url type: https -- Some packages may not be found!
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
Download error: unknown url type: https -- Some packages may not be found!
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')

Downloading get_pip.py and running it with the stock OS X-supplied python 2.6: 下载get_pip.py并使用库存OS X提供的python 2.6运行它:

# python2.6 ./get_pip.py 
Traceback (most recent call last):
  File "./get_pip.py", line 17868, in <module>
    main()
  File "./get_pip.py", line 162, in main
    bootstrap(tmpdir=tmpdir)
  File "./get_pip.py", line 82, in bootstrap
    import pip
  File "/tmp/tmpVJBvaW/pip.zip/pip/__init__.py", line 15, in <module>
  File "/tmp/tmpVJBvaW/pip.zip/pip/vcs/subversion.py", line 9, in <module>
  File "/tmp/tmpVJBvaW/pip.zip/pip/index.py", line 30, in <module>
  File "/tmp/tmpVJBvaW/pip.zip/pip/wheel.py", line 34, in <module>
  File "/tmp/tmpVJBvaW/pip.zip/pip/_vendor/__init__.py", line 92, in load_module
ImportError: No module named 'pip._vendor.distlib.scripts'


$ python2.6 --version
Python 2.6.9

With python2.7, either method works fine. 使用python2.7,任何一种方法都可以。

Download the source file here . 此处下载源文件。 Then do 然后做

>> cd ~/Downloads
>> tar -xzvf pip-7.0.1.tar.gz 

(replacing ~/Downloads if necessary). (必要时替换~/Downloads )。 Then 然后

>> cd pip-7.0.1
>> sudo python2.6 setup.py install
>> cd

(the last cd is used to leave the build directory). (最后一张cd用于离开构建目录)。 Now you should be able to run 现在你应该能够跑了

>> python2.6 -c 'import pip;print pip.__version__'
7.0.1

By default, pip (when installed from source) should be installed into /usr/local/bin . 默认情况下,pip(从源安装时)应安装到/usr/local/bin To check: 去检查:

>> /usr/local/bin/pip --version
pip 7.0.1 from /Library/Python/2.6/site-packages/pip-7.0.1-py2.6.egg (python 2.6)

Now you can install your favorite packages using 现在您可以使用安装自己喜欢的包

>> /usr/local/bin/pip install package
>> python2.6 -c 'import package'

If you have conflicting versions of pip in /usr/local/bin you can try this ridiculous one liner: 如果/usr/local/binpip版本存在冲突,你可以试试这个荒谬的单行:

>> python -c 'import os;dir="/usr/local/bin";[ os.system("echo %s/%s: && %s/%s --version"%(dir,s,dir,s)) for s in os.listdir("/usr/local/bin") if s.startswith("pip")  ]'
/usr/local/bin/pip:
pip 7.0.1 from /Library/Python/2.6/site-packages/pip-7.0.1-py2.6.egg (python 2.6)
/usr/local/bin/pip2:
pip 7.0.1 from /Library/Python/2.6/site-packages/pip-7.0.1-py2.6.egg (python 2.6)
/usr/local/bin/pip2.6:
pip 7.0.1 from /Library/Python/2.6/site-packages/pip-7.0.1-py2.6.egg (python 2.6)

to find the one linked to py2.6. 找到一个链接到py2.6的那个。 (in my case they are all the same) (在我的情况下,他们都是一样的)

By default Homebrew provides pip command via: brew install python . 默认情况下, Homebrew通过: brew install python提供pip命令。

So try installing Python using Homebrew. 所以尝试使用Homebrew安装Python。 Try to not use sudo when working with brew . 尝试使用brew时不要使用sudo

To verify which files are installed with your Python package, try: 要验证Python包中安装了哪些文件,请尝试:

$ brew list python
/usr/local/Cellar/python/2.7.9/bin/pip
/usr/local/Cellar/python/2.7.9/bin/pip2
/usr/local/Cellar/python/2.7.9/bin/pip2.7
...

which should consist pip . 应该包括pip

After installation you should symlink your formula's installed files by: 安装后,您应该通过以下方式对公式的已安装文件进行符号链接:

brew link python

which should create the right symbolic links (such as /usr/local/bin/pip pointing to your Cellar/python/2.?.?/bin/pip ) 应该创建正确的符号链接(例如/usr/local/bin/pip指向你的Cellar/python/2.?.?/bin/pip

If you've permission issue, you may fix it by: 如果您有权限问题,可以通过以下方式修复:

sudo chgrp -R admin /usr/local /Library/Caches/Homebrew
sudo chmod -R g+w /usr/local /Library/Caches/Homebrew

and make sure your user is in admin group ( id -Gn $USER ). 并确保您的用户在管理员组( id -Gn $USER )。

Then re-link it again: 然后再次重新链接:

brew unlink python && brew link python

To test dry-run, unlink and run: brew link -n python to see links of files which brew would link. 要测试干运行,取消链接并运行: brew link -n python以查看brew链接的文件链接。

After linking is successful, make sure that your PATH system variable have /usr/local , if not, add: 链接成功后,确保您的PATH系统变量具有/usr/local ,如果没有,请添加:

export PATH=/usr/local/sbin:/usr/local/bin:$PATH

to your ~/.bashrc file. 到你的~/.bashrc文件。

If successful, your pip should work now. 如果成功,你的pip现在应该工作。


If you don't want to use Homebrew or you have two Pythons installed on your Mac, you can alternatively install it via: 如果您不想使用Homebrew或者您的Mac上安装了两个Pythons,您也可以通过以下方式安装它:

sudo easy_install pip

Your error: 你的错误:

Download error: unknown url type: https 下载错误:未知网址类型:https

means that your Python can't handle HTTPS protocol without having SSL support, so try installing: openssl package (on Linux either libssl-dev or openssl-devel ). 意味着您的Python无法在没有SSL支持的情况下处理HTTPS协议,因此请尝试安装: openssl package(在Linux上使用libssl-devopenssl-devel )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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