我使用的是Mac OS X 10.10。我想使用pip为我的自制软件安装版本安装软件包(位于/usr/local/bin/python
,这是一个指向/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin
的别名)。此版本的网站套件似乎在此处:/usr/local/lib/python2.7/site-packages/
。
which python
返回/usr/local/bin/python
which pip
返回/usr/local/bin/pip
这些对我来说似乎是正确的。
尝试pip install pylzma
之类的内容会返回:
Collecting pylzma
Installing collected packages: pylzma
Successfully installed pylzma
You are using pip version 8.0.2, however version 8.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
但是pip list
未显示pylzma
要安装。看起来pip会将软件包安装到/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
(Mac OS X附带的python)。
如何将pip安装到我的自制的python中?
我已尝试过类似问题的一些建议:
export PATH=/usr/local/bin/python:${PATH}
。pip install --install-option="--prefix=/usr/local/lib/python2.7" pylzma
。#!/usr/local/bin/python
/usr/local/bin/python -m pip install pylzma
。但这些都不起作用。我也尝试将pip升级到8.1.1,但这完全打破了pip。人们建议使用virtualenv
,但据我所知,我无法在没有点的情况下安装它。
当我输入python -m pip
时,它会说:
Usage:
/usr/local/opt/python/bin/python2.7 -m pip <command> [options]
这可能是个问题吗?
答案 0 :(得分:2)
我的问题是我的/Users/<username>/.pydistutils.cfg
包含以下内容:
[easy_install]
# set the default location to install packages
install_dir = /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
[install]
install_lib = /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
install_scripts = ~/bin
我将其更改为:
[easy_install]
# set the default location to install packages
install_dir = /usr/local/lib/python2.7/site-packages
[install]
install_lib = /usr/local/lib/python2.7/site-packages
install_scripts = ~/bin
这似乎奏效了。 pip install
现在将软件包安装到所需的位置/usr/local/lib/python2.7/site-packages
。
但是,我有持续的路径问题。
import pylzma
仍然给了我ImportError: No module named pylzma
。
并在终端中运行jupyter notebook
会产生-bash: jupyter: command not found
。 /Users/<username>/bin/jupyter notebook
确实执行了,但我ImportError: No module named markupsafe
,尽管存在/usr/local/lib/python2.7/site-packages/MarkupSafe-0.23.dist-info
。