- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
在分发应用程序时将所有的鸡蛋合并到一个 zip 文件中会很方便,这样您只需要分发一个 zip 文件和一个可执行文件(一些自定义二进制文件,只需启动, 加载 zip 文件的主要功能并启动 python 或类似功能)。
我在网上看到过一些关于这样做的讨论,但没有关于如何实际做到这一点的示例。
我知道您可以(如果它是 zip 安全的)将鸡蛋转换为 zip 文件。
我不确定的是:
你能以某种方式将所有鸡蛋合并成一个 zip 文件吗?如果有,怎么做?
您将如何从特定的 egg 加载和运行代码?
您如何确保该 egg 中的代码可以访问所有依赖项(即 zip 文件中的其他 Egg)?
人们经常问这类问题并得到诸如此类的答案;使用 py2exe。是的,我明白了,这是一种解决方案。不过,这不是我要在这里问的问题...
最佳答案
您可以使用常规 Python 工具自动完成大部分工作。让我们从干净的 virtualenv 开始。
[zart@feena ~]$ mkdir ziplib-demo
[zart@feena ~]$ cd ziplib-demo
[zart@feena ziplib-demo]$ virtualenv .
New python executable in ./bin/python
Installing setuptools.............done.
Installing pip...............done.
现在让我们安装一组将进入压缩库的软件包。诀窍是强制将它们安装到特定目录中。
(注意:不要在命令行或 pip.conf/pip.ini 中使用 --egg 选项,因为它会破坏文件布局,使其无法在 zip 中导入)
[zart@feena ziplib-demo]$ bin/pip install --install-option --install-lib=$PWD/unpacked waitress
Downloading/unpacking waitress
Downloading waitress-0.8.5.tar.gz (112kB): 112kB downloaded
Running setup.py egg_info for package waitress
Requirement already satisfied (use --upgrade to upgrade): setuptools in ./lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg (from waitress)
Installing collected packages: waitress
Running setup.py install for waitress
Installing waitress-serve script to /home/zart/ziplib-demo/bin
Successfully installed waitress
Cleaning up...
更新:pip 现在有 -t <path>
开关,其作用与 --install-option --install-lib=
相同.
现在让我们将它们全部打包到一个 zip 中
[zart@feena ziplib-demo]$ cd unpacked
[zart@feena unpacked]$ ls
waitress waitress-0.8.5-py2.7.egg-info
[zart@feena unpacked]$ zip -r9 ../library.zip *
adding: waitress/ (stored 0%)
adding: waitress/receiver.py (deflated 71%)
adding: waitress/server.pyc (deflated 64%)
adding: waitress/utilities.py (deflated 62%)
adding: waitress/trigger.pyc (deflated 63%)
adding: waitress/trigger.py (deflated 61%)
adding: waitress/receiver.pyc (deflated 60%)
adding: waitress/adjustments.pyc (deflated 51%)
adding: waitress/compat.pyc (deflated 56%)
adding: waitress/adjustments.py (deflated 60%)
adding: waitress/server.py (deflated 68%)
adding: waitress/channel.py (deflated 72%)
adding: waitress/task.pyc (deflated 57%)
adding: waitress/tests/ (stored 0%)
adding: waitress/tests/test_regression.py (deflated 63%)
adding: waitress/tests/test_functional.py (deflated 88%)
adding: waitress/tests/test_parser.pyc (deflated 76%)
adding: waitress/tests/test_trigger.pyc (deflated 73%)
adding: waitress/tests/test_init.py (deflated 72%)
adding: waitress/tests/test_utilities.pyc (deflated 78%)
adding: waitress/tests/test_buffers.pyc (deflated 79%)
adding: waitress/tests/test_trigger.py (deflated 82%)
adding: waitress/tests/test_buffers.py (deflated 86%)
adding: waitress/tests/test_runner.py (deflated 75%)
adding: waitress/tests/test_init.pyc (deflated 69%)
adding: waitress/tests/__init__.pyc (deflated 21%)
adding: waitress/tests/support.pyc (deflated 48%)
adding: waitress/tests/test_utilities.py (deflated 73%)
adding: waitress/tests/test_channel.py (deflated 87%)
adding: waitress/tests/test_task.py (deflated 87%)
adding: waitress/tests/test_functional.pyc (deflated 82%)
adding: waitress/tests/__init__.py (deflated 5%)
adding: waitress/tests/test_compat.pyc (deflated 53%)
adding: waitress/tests/test_receiver.pyc (deflated 79%)
adding: waitress/tests/test_adjustments.py (deflated 78%)
adding: waitress/tests/test_adjustments.pyc (deflated 74%)
adding: waitress/tests/test_server.pyc (deflated 73%)
adding: waitress/tests/fixtureapps/ (stored 0%)
adding: waitress/tests/fixtureapps/filewrapper.pyc (deflated 59%)
adding: waitress/tests/fixtureapps/getline.py (deflated 37%)
adding: waitress/tests/fixtureapps/nocl.py (deflated 47%)
adding: waitress/tests/fixtureapps/sleepy.pyc (deflated 44%)
adding: waitress/tests/fixtureapps/echo.py (deflated 40%)
adding: waitress/tests/fixtureapps/error.py (deflated 52%)
adding: waitress/tests/fixtureapps/nocl.pyc (deflated 48%)
adding: waitress/tests/fixtureapps/getline.pyc (deflated 32%)
adding: waitress/tests/fixtureapps/writecb.pyc (deflated 42%)
adding: waitress/tests/fixtureapps/toolarge.py (deflated 37%)
adding: waitress/tests/fixtureapps/__init__.pyc (deflated 20%)
adding: waitress/tests/fixtureapps/writecb.py (deflated 50%)
adding: waitress/tests/fixtureapps/badcl.pyc (deflated 44%)
adding: waitress/tests/fixtureapps/runner.pyc (deflated 58%)
adding: waitress/tests/fixtureapps/__init__.py (stored 0%)
adding: waitress/tests/fixtureapps/filewrapper.py (deflated 74%)
adding: waitress/tests/fixtureapps/runner.py (deflated 41%)
adding: waitress/tests/fixtureapps/echo.pyc (deflated 42%)
adding: waitress/tests/fixtureapps/groundhog1.jpg (deflated 24%)
adding: waitress/tests/fixtureapps/error.pyc (deflated 48%)
adding: waitress/tests/fixtureapps/sleepy.py (deflated 42%)
adding: waitress/tests/fixtureapps/toolarge.pyc (deflated 43%)
adding: waitress/tests/fixtureapps/badcl.py (deflated 45%)
adding: waitress/tests/support.py (deflated 52%)
adding: waitress/tests/test_task.pyc (deflated 78%)
adding: waitress/tests/test_channel.pyc (deflated 78%)
adding: waitress/tests/test_regression.pyc (deflated 68%)
adding: waitress/tests/test_parser.py (deflated 80%)
adding: waitress/tests/test_server.py (deflated 78%)
adding: waitress/tests/test_receiver.py (deflated 87%)
adding: waitress/tests/test_compat.py (deflated 51%)
adding: waitress/tests/test_runner.pyc (deflated 72%)
adding: waitress/__init__.pyc (deflated 50%)
adding: waitress/channel.pyc (deflated 58%)
adding: waitress/runner.pyc (deflated 54%)
adding: waitress/buffers.py (deflated 74%)
adding: waitress/__init__.py (deflated 61%)
adding: waitress/runner.py (deflated 58%)
adding: waitress/parser.py (deflated 69%)
adding: waitress/compat.py (deflated 69%)
adding: waitress/buffers.pyc (deflated 69%)
adding: waitress/utilities.pyc (deflated 60%)
adding: waitress/parser.pyc (deflated 53%)
adding: waitress/task.py (deflated 72%)
adding: waitress-0.8.5-py2.7.egg-info/ (stored 0%)
adding: waitress-0.8.5-py2.7.egg-info/dependency_links.txt (stored 0%)
adding: waitress-0.8.5-py2.7.egg-info/installed-files.txt (deflated 83%)
adding: waitress-0.8.5-py2.7.egg-info/top_level.txt (stored 0%)
adding: waitress-0.8.5-py2.7.egg-info/PKG-INFO (deflated 65%)
adding: waitress-0.8.5-py2.7.egg-info/not-zip-safe (stored 0%)
adding: waitress-0.8.5-py2.7.egg-info/SOURCES.txt (deflated 71%)
adding: waitress-0.8.5-py2.7.egg-info/entry_points.txt (deflated 33%)
adding: waitress-0.8.5-py2.7.egg-info/requires.txt (deflated 5%)
[zart@feena unpacked]$ cd ..
请注意,这些文件应该在 zip 的顶部,不能只是 zip -r9 library.zip unpacked
检查结果:
[zart@feena ziplib-demo]$ PYTHONPATH=library.zip python
Python 2.7.1 (r271:86832, Apr 12 2011, 16:15:16)
[GCC 4.6.0 20110331 (Red Hat 4.6.0-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import waitress
>>> waitress
<module 'waitress' from '/home/zart/ziplib-demo/library.zip/waitress/__init__.pyc'>
>>>
>>> from wsgiref.simple_server import demo_app
>>> waitress.serve(demo_app)
serving on http://0.0.0.0:8080
^C>>>
更新:从 python 3.5 开始还有 zipapp module这可以帮助将整个包捆绑到 .pyz 文件中。对于更复杂的需求pyinstaller , py2exe或 py2app可能更符合要求。
关于python - 如何将所有 python 代码捆绑到一个 zip 文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17486578/
我尝试理解[c代码 -> 汇编]代码 void node::Check( data & _data1, vector& _data2) { -> push ebp -> mov ebp,esp ->
我需要在当前表单(代码)的上下文中运行文本文件中的代码。其中一项要求是让代码创建新控件并将其添加到当前窗体。 例如,在Form1.cs中: using System.Windows.Forms; ..
我有此 C++ 代码并将其转换为 C# (.net Framework 4) 代码。有没有人给我一些关于 malloc、free 和 sprintf 方法的提示? int monate = ee; d
我的网络服务器代码有问题 #include #include #include #include #include #include #include int
给定以下 html 代码,将列表中的第三个元素(即“美丽”一词)以斜体显示的 CSS 代码是什么?当然,我可以给这个元素一个 id 或一个 class,但 html 代码必须保持不变。谢谢
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
我试图制作一个宏来避免重复代码和注释。 我试过这个: #define GrowOnPage(any Page, any Component) Component.Width := Page.Surfa
我正在尝试将我的旧 C++ 代码“翻译”成头条新闻所暗示的 C# 代码。问题是我是 C# 中的新手,并不是所有的东西都像 C++ 中那样。在 C++ 中这些解决方案运行良好,但在 C# 中只是不能。我
在 Windows 10 上工作,R 语言的格式化程序似乎没有在 Visual Studio Code 中完成它的工作。我试过R support for Visual Studio Code和 R-T
我正在处理一些报告(计数),我必须获取不同参数的计数。非常简单但乏味。 一个参数的示例查询: qCountsEmployee = ( "select count(*) from %s wher
最近几天我尝试从 d00m 调试网络错误。我开始用尽想法/线索,我希望其他 SO 用户拥有可能有用的宝贵经验。我希望能够提供所有相关信息,但我个人无法控制服务器环境。 整个事情始于用户注意到我们应用程
我有一个 app.js 文件,其中包含如下 dojo amd 模式代码: require(["dojo/dom", ..], function(dom){ dom.byId('someId').i
我对“-gencode”语句中的“code=sm_X”选项有点困惑。 一个例子:NVCC 编译器选项有什么作用 -gencode arch=compute_13,code=sm_13 嵌入库中? 只有
我为我的表格使用 X-editable 框架。 但是我有一些问题。 $(document).ready(function() { $('.access').editable({
我一直在通过本教程学习 flask/python http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-wo
我想将 Vim 和 EMACS 用于 CNC、G 代码和 M 代码。 Vim 或 EMACS 是否有任何语法或模式来处理这种类型的代码? 最佳答案 一些快速搜索使我找到了 this vim 和 thi
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve this
这个问题在这里已经有了答案: Enabling markdown highlighting in Vim (5 个回答) 6年前关闭。 当我在 Vim 中编辑包含 Markdown 代码的 READM
我正在 Swift3 iOS 中开发视频应用程序。基本上我必须将视频 Assets 和音频与淡入淡出效果合并为一个并将其保存到 iPhone 画廊。为此,我使用以下方法: private func d
pipeline { agent any stages { stage('Build') { steps { e
我是一名优秀的程序员,十分优秀!