简体   繁体   English

使用pip或easy_install从repos安装Python包

[英]Python package install using pip or easy_install from repos

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. 有没有办法使用其中一个Package安装程序(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. easy_install获取tar.gz并使用安装在python2.6的dist-packages文件夹中的setup.py install进行安装。 Is there a way to configure it, or pip to use the source version control system (SVN/GIT/Hg/Bzr) instead. 有没有办法配置它,或者pip来使用源版本控制系统(SVN / GIT / Hg / Bzr)。

Using pip this is quite easy. 使用pip这很容易。 For instance: 例如:

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 ). Pip将自动克隆源代码并运行“setup.py develop”,以便将其安装到您的环境中(希望这是一个虚拟环境 )。 Git, Subversion, Bazaar and Mercurial are all supported. 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). 然后,您还可以运行“pip freeze”,它将输出您当前安装的软件包的列表及其确切版本(包括,对于开发安装,来自VCS的确切修订)。 You can put this straight into a requirements file and later run 您可以直接将其放入需求文件中,然后再运行

pip install -r requirements.txt

to install that same set of packages at the exact same versions. 在完全相同的版本上安装同一组软件包。

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. 正如其他响应所示,您应该尝试阅读“setuptools”文档以了解更多信息。 "setup.py develop" is a really useful feature! “setup.py develop”是一个非常有用的功能! 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: 尝试将它与virtualenv结合使用,您可以轻松地“setup.py开发”,而不会使用您只是临时开发的软件包来破坏系统范围的Python:

http://pypi.python.org/pypi/virtualenv

easy_install has support for downloading specific versions. easy_install支持下载特定版本。 For example: 例如:

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. 还支持svn checkout,但使用它并不能从手动版本中获得很多好处。 See the manual for more information above. 有关上述更多信息,请参阅手册。

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. 除非您正在开发有问题的软件包,否则能够切换到特定分支很少有用,然后无论如何将它们安装在站点包中通常都不是一个好主意。

easy_install accepts a URL for the source tree too. easy_install也接受源树的URL。 Works at least when the sources are in Subversion. 至少在源代码处于Subversion时起作用。

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

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