本文介绍了用virtualenv分发python代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一些具有一些外部依赖性的python代码分发给仅安装了核心python的机器(以及不熟悉easy_install的用户等).

I want to distribute some python code, with a few external dependencies, to machines with only core python installed (and users that unfamiliar with easy_install etc.).

我想知道是否可以将virtualenv用于此目的?我应该能够编写一些bash脚本来触发virtualenv(使用合适的软件包),然后运行我的代码..但这似乎有些混乱,我想知道是否要重新发明轮子?

I was wondering if perhaps virtualenv can be used for this purpose? I should be able to write some bash scripts that trigger the virtualenv (with the suitable packages) and then run my code.. but this seems somewhat messy, and I'm wondering if I'm re-inventing the wheel?

有没有简单的解决方案来分发具有依赖性的python代码,理想情况下,在客户端计算机上不需要sudo?

Are there any simple solutions to distributing python code with dependencies, that ideally doesn't require sudo on client machines?

推荐答案

构建- http://pypi.python.org/pypi/zc.buildout
作为示例,请看我的干净项目: http://hg.jackleo.info/hyde-0.5.3-buildout-enviroment/src 它只有2个文件具有魔力,而Makefile则是可选的,但您需要bootstrap.py(使文件下载,但只能在Linux). buildout.cfg是主要文件,您可以在其中编写依赖项并配置项目的放置方式.
要获取bootstrap.py,只需从 http://svn下载.zope.org/repos/main/zc.buildout/trunk/bootstrap/bootstrap.py
然后运行python bootstap.pybin/buildout.我不建议在本地安装buildout,尽管可以,只需使用一次引导下载即可.

Buildout - http://pypi.python.org/pypi/zc.buildout
As sample look at my clean project: http://hg.jackleo.info/hyde-0.5.3-buildout-enviroment/src its only 2 files that do the magic, more over Makefile is optional but then you'll need bootstrap.py (Make file downloads it, but it runs only on Linux). buildout.cfg is the main file where you write dependency's and configuration how project is laid down.
To get bootstrap.py just download from http://svn.zope.org/repos/main/zc.buildout/trunk/bootstrap/bootstrap.py
Then run python bootstap.py and bin/buildout. I do not recommend to install buildout locally although it is possible, just use the one bootstrap downloads.

我必须承认,扩展不是最简单的解决方案,而是真正强大的解决方案.因此学习是值得的.

I must admit that buildout is not the easiest solution but its really powerful. So learning is worth time.

更新2014-05-30
由于它最近被投票并被用作答案(可能是答案),所以我希望通知几乎没有更改.

UPDATE 2014-05-30
Since It was recently up-voted and used as an answer (probably), I wan to notify of few changes.

首先-现在可以从github https://raw下载.githubusercontent.com/buildout/buildout/master/bootstrap/bootstrap.py

First of - buildout is now downloaded from github https://raw.githubusercontent.com/buildout/buildout/master/bootstrap/bootstrap.py

该Hyde项目很可能会由于第2个重大更改而失败.

That hyde project would probably fail due to buildout 2 breaking changes.

在这里您可以找到更好的示例 http://www.buildout.org/zh_CN/latest/docs/index.html 另外,我也建议您查看与Buildout相关的链接的集合"部分,其中可能包含您项目的信息.

Here you can find better samples http://www.buildout.org/en/latest/docs/index.html also I want to suggest to look at "collection of links related to Buildout" part, it might contain info for your project.

第二,我个人更喜欢可以使用python安装的setup.py脚本.有关蛋结构的更多信息,请参见 http://peak.telecommunity.com/DevCenter/PythonEggs,如果这看起来太吓人,请查找google(查询python egg).在我看来,它实际上比构建更简单(绝对易于调试),并且它可能更有用,因为它可以更轻松地分发并借助virtualenv进行安装,也可以在全球范围内安装,而构建则必须提供所有功能.始终使用源代码来构建脚本.

Secondly I am personally more in favor of setup.py script that can be installed using python. More about the egg structure can be found here http://peak.telecommunity.com/DevCenter/PythonEggs and if that looks too scary - look up google (query for python egg). It's actually more simple in my opinion than buildout (definitely easier to debug) as well as it is probably more useful since it can be distributed more easily and installed anywhere with a help of virtualenv or globally where with buildout you have to provide all of the building scripts with the source all of the time.

这篇关于用virtualenv分发python代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-17 17:02