在 Ubuntu 10.04 上默认安装了 Python 2.6,然后我安装了 Python 2.7。如何使用 pip install
安装 Python 2.7 的软件包。
例如:
pip install beautifulsoup4
默认情况下为 Python 2.6 安装 BeautifulSoup
当我做:
import bs4
在 Python 2.6 中它可以工作,但在 Python 2.7 中它说:
No module named bs4
最佳答案
针对要安装新包的 Python 实例使用安装的 pip
版本。
在许多发行版中,可能有单独的 python2.6-pip
和 python2.7-pip
包,使用二进制名称调用,例如 pip-2.6
和 pip-2.7
。如果您的发行版中没有为所需目标打包 pip,您可能会寻找 setuptools 或 easyinstall 包,或者使用 virtualenv(它总是在生成的环境中包含 pip)。
pip 的网站 includes installation instructions ,如果你在你的发行版中找不到任何东西。
关于python - 使用 pip 为特定的 python 版本安装模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10919569/