创建便携式 Django 应用程序 - 需要帮助
我正在构建一个 Django 应用程序,我可以在 Ubuntu Linux 主机上轻松运行(测试:))。我想打包没有源代码的应用程序并将其分发到另一台生产机器。理想情况下,应用程序可以通过 ./runapp 命令运行,该命令启动运行 python/django 代码的 CherryPy 服务器。
我发现了几种执行此操作的方法:
- 仅分发 .pyc 文件并在目标计算机上构建和安装所有要求。
- 使用众多工具之一将 Python 应用程序打包到可分发包中。
我真的很喜欢 nr.2 选项,我希望包含我的 Django 应用程序,这样就可以分发它而无需安装或配置其他东西。在互联网上搜索给我带来的问题多于答案,并且让我感到非常酸涩,Django 包装是一门人人都知道但无人谈论的神秘艺术。 :)
我尝试过冻结(失败),Cx_freeze(简单安装版本失败,存储库版本有效,但应用程序输出失败)并在 dbuilder.py 上呈红色(应该可以工作,但实际上不起作用 - 我猜)。如果我理解正确的话,大多数问题都源于 Django 导入模块的方式(示例),但我不知道如何解决它。
如果有人可以在线提供有关打包/分发独立 Django 应用程序的任何指示或良好资源,我将非常高兴。
I'm building a Django app, which I comfortably run (test :)) on a Ubuntu Linux host. I would like to package the app without source code and distribute it to another production machine. Ideally the app could be run by ./runapp command which starts a CherryPy server that runs the python/django code.
I've discovered several ways of doing this:
- Distributing the .pyc files only and building and installing all the requirements on target machine.
- Using one of the many tools to package Python apps into a distributable package.
I'm really gunning for nr.2 option, I'd like to have my Django app contained, so it's possible to distribute it without needing to install or configure additional things. Searching the interwebs provided me with more questions than answers and a very sour taste that Django packing is an arcane art that everybody knows but nobody speaks about. :)
I've tried Freeze (fails), Cx_freeze (easy install version fails, repository version works, but the app output fails) and red up on dbuilder.py (which is supposed to work but doesn't work really - I guess). If I understand correctly most problems originate form the way that Django imports modules (example) but I have no idea how to solve it.
I'll be more than happy if anyone can provide any pointers or good resources online regarding packing/distributing standalone Django applications.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您将发行版基于 setuptools (一种增强标准 Python 发行版机制的工具 distutils)。
使用 setuptools,您应该能够创建一个包含您的应用程序的 Python Egg。 Egg 的元数据可以包含将由
easy_install
自动安装的依赖项列表(可以包括 Django + 您使用的任何第三方模块/包)。setuptools/distutils 发行版可以包含将安装到
/usr/bin
的脚本,因此您可以这样包含runapp
脚本。如果您不熟悉 virtualenv,我建议您也看一下。它是一种创建隔离的 Python 环境的方法,对于测试您的发行版非常有用。
这是一篇博客文章,其中包含有关 virtualenv 的一些信息,以及有关其他一些值得了解的工具的讨论:现代 Python 黑客工具:Virtualenv、Fabric 和 Pip
I suggest you base your distro on setuptools (a tool that enhances the standard Python distro mechanizm distutils).
Using setuptools, you should be able to create a Python egg containing your application. The egg's metadata can contain a list of dependencies that will be automatically installed by
easy_install
(can include Django + any third-party modules/packages that you use).setuptools/distutils distros can include scripts that will be installed to
/usr/bin
, so that's how you can include yourrunapp
script.If you're not familiar with virtualenv, I suggest you take a look at that as well. It is a way to create isolated Python environments, it will be very useful for testing your distro.
Here's a blog post with some info on virtualenv, as well as a discussion about a couple of other nice to know tools: Tools of the Modern Python Hacker: Virtualenv, Fabric and Pip
--noreload 选项将停止 Django 自动检测哪些模块已更改。我不知道这是否能解决问题,但可能会。
另一种选择(但并不理想)是通过将某些核心功能打包为 dll 来隐藏某些核心功能,纯文本代码将调用该 dll。
The --noreload option will stop Django auto-detecting which modules have changed. I don't know if that will fix it, but it might.
Another option (and it's not ideal) is to obscure some of your core functionality by packaging it as a dll, which your plain text code will call.