使用 pip 或 easy_install 从 repos 安装 Python 包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1033897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python package install using pip or easy_install from repos
提问by Lakshman Prasad
The simplest way to deal with python package installations, so far, to me, has been to check out the source from the source control system and then add a symbolic link in the python dist-packages folder.
到目前为止,对我来说,处理 python 包安装的最简单方法是从源代码控制系统中检查源代码,然后在 python dist-packages 文件夹中添加一个符号链接。
Clearly since source control provides the complete control to downgrade, upgrade to any branch, tag, it works very well.
显然,由于源代码控制提供了对降级、升级到任何分支、标记的完整控制,因此它运行得非常好。
Is there a way using one of the Package installers (easy_install or pip or other), one can achieve the same.
有没有办法使用其中一个包安装程序(easy_install 或 pip 或其他),可以实现相同的目标。
easy_install obtains the tar.gz and install them using the setup.py install which installs in the dist-packages folder in python2.6. Is there a way to configure it, or pip to use the source version control system (SVN/GIT/Hg/Bzr) instead.
easy_install 获取 tar.gz 并使用 setup.py install 安装它们,该安装安装在 python2.6 的 dist-packages 文件夹中。有没有办法配置它,或者pip使用源版本控制系统(SVN/GIT/Hg/Bzr)代替。
回答by Carl Meyer
Using pipthis is quite easy. For instance:
使用pip这很容易。例如:
pip install -e hg+http://bitbucket.org/andrewgodwin/south/#egg=South
Pip will automatically clone the source repo and run "setup.py develop" for you to install it into your environment (which hopefully is a virtualenv). Git, Subversion, Bazaar and Mercurial are all supported.
Pip 将自动克隆源代码库并运行“setup.py develop”让您将其安装到您的环境中(希望是一个virtualenv)。Git、Subversion、Bazaar 和 Mercurial 都受支持。
You can also then run "pip freeze" and it will output a list of your currently-installed packages with their exact versions (including, for develop-installs, the exact revision from the VCS). You can put this straight into a requirements file and later run
然后,您还可以运行“pip freeze”,它会输出您当前安装的软件包列表及其确切版本(对于开发安装,包括来自 VCS 的确切修订版)。您可以将其直接放入需求文件中,然后再运行
pip install -r requirements.txt
to install that same set of packages at the exact same versions.
以完全相同的版本安装同一组软件包。
回答by Brandon Rhodes
If you download or check out the source distribution of a package — the one that has its "setup.py" inside of it — then if the package is based on the "setuptools" (which also power easy_install), you can move into that directory and say:
如果你下载或查看一个包的源代码分发——里面有它的“setup.py”——那么如果这个包基于“setuptools”(它也支持easy_install),你可以进入那个目录并说:
$ python setup.py develop
and it will create the right symlinks in dist-packages so that the .py files in the source distribution are the ones that get imported, rather than copies installed separately (which is what "setup.py install" would do — create separate copies that don't change immediately when you edit the source code to try a change).
它会在 dist-packages 中创建正确的符号链接,以便源代码分发中的 .py 文件是被导入的文件,而不是单独安装的副本(这就是“setup.py install”会做的 - 创建单独的副本当您编辑源代码以尝试更改时不要立即更改)。
As the other response indicates, you should try reading the "setuptools" documentation to learn more. "setup.py develop" is a really useful feature! Try using it in combination with a virtualenv, and you can "setup.py develop" painlessly and without messing up your system-wide Python with packages you are only developing on temporarily:
正如其他回复所表明的,您应该尝试阅读“setuptools”文档以了解更多信息。“setup.py develop”是一个非常有用的功能!尝试将它与 virtualenv 结合使用,您可以轻松地“setup.py 开发”,并且不会用您只是暂时开发的包来搞乱系统范围的 Python:
http://pypi.python.org/pypi/virtualenv
回答by Lennart Regebro
easy_install has support for downloading specific versions. For example:
easy_install 支持下载特定版本。例如:
easy_install python-dateutil==1.4.0
Will install v1.4, while the latest version 1.4.1 would be picked if no version was specified.
将安装 v1.4,如果未指定版本,则将选择最新版本 1.4.1。
There is also support for svn checkouts, but using that doesn't give you much benefits from your manual version. See the manual for more information above.
还支持 svn checkouts,但使用它并不能从手动版本中获得太多好处。有关上述更多信息,请参阅手册。
Being able to switch to specific branches is rarely useful unless you are developing the packages in question, and then it's typically not a good idea to install them in site-packages anyway.
除非您正在开发有问题的包,否则能够切换到特定分支很少有用,然后无论如何将它们安装在站点包中通常不是一个好主意。
回答by Heikki Toivonen
easy_install accepts a URL for the source tree too. Works at least when the sources are in Subversion.
easy_install 也接受源树的 URL。至少当源在 Subversion 时有效。