如何为Windows用户部署Python?
我很快就会推出一个 测试版应用,并且可以选择在 Python。
该应用程序将以 Mac OS X 和 Windows 为目标,而我的问题是 Windows,而 Python 通常不是展示。
我的实际方法是静默运行 Python 2.6 安装。但是,我面临默认情况下未激活的问题,并且使用 时未设置路径命令行选项。我担心如果之前安装过 Python 并且升级到新版本,这可能会破坏其他东西......
所以,我想知道如何干净地完成此操作。如果我复制整个 Python 2.6 目录,并将其放在我的应用程序的子目录中并在那里安装所有内容,可以吗?或者使用 virtualenv 可以运行不同版本的 Python(如果机器中已经安装了 Python?)。
用DLL嵌入Python之前我也玩过,发现很简单,但是我失去了调试能力,所以我改用命令行插件。
我从命令行执行插件并读取 STDOUT 和 STDERR 输出。该应用程序是用 Delphi/Lazarus 制作的。我安装了其他模块,如 JSON 和 RPC 客户端、Win32com、ORM 等。我使用 bitrock 创建安装程序。
更新:最终用户是小企业主,Python 脚本是由开发人员编写的。我想避免部署中的任何额外步骤,因此我想要一个完全集成的设置。
I'm soon to launch a beta app and this have the option to create custom integration scripts on Python.
The app will target Mac OS X and Windows, and my problem is with Windows where Python normally is not present.
My actual aproach is silently run the Python 2.6 install. However I face the problem that is not activated by default and the path is not set when use the command line options. And I fear that if Python is installed before and I upgrade to a new version this could break something else...
So, I wonder how this can be done cleanly. Is it OK if I copy the whole Python 2.6 directory, and put it in a sub-directory of my app and install everything there? Or with virtualenv is posible run diferents versions of Python (if Python is already installed in the machine?).
I also play before embedding Python with a DLL, and found it easy but I lost the ability to debug, so I switch to command-line plug-ins.
I execute the plug-ins from command line and read the STDOUT and STDERR output. The app is made with Delphi/Lazarus. I install others modules like JSON and RPC clients, Win32com, ORM, etc. I create the installer with bitrock.
UPDATE: The end-users are small business owners, and the Python scripts are made by developers. I want to avoid any additional step in the deployment, so I want a fully integrated setup.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将 Portable Python 文件夹从安装程序复制到与 Delphi/Lazarus 应用程序相同的文件夹中。为此适当设置所有路径。
Copy a Portable Python folder out of your installer, into the same folder as your Delphi/Lazarus app. Set all paths appropriately for that.
您可以尝试使用 py2exe。它创建一个 .exe 文件,其中已包含 Python!
You might try using py2exe. It creates a .exe file with Python already included!
使用 P4D 将 python 解释器集成到您的 Delphi 应用中。这些组件实际上可以工作,而且是双向的(Delphi 类作为二进制扩展暴露给 Python,以及 Delphi 内部的 Python 解释器)。我还在 Google 代码“问题”页面上看到了 Lazarus 兼容性的补丁,但似乎那里可能存在一些未解决的问题。
Integrate the python interpreter into your Delphi app with P4D. These components actually work, and in both directions too (Delphi classes exposed to Python as binary extensions, and Python interpreter inside Delphi). I also saw a patch for Lazarus compatibility on the Google Code "issues" page, but it seems there might be some unresolved issues there.
我认为将 .EXE 打包与 PyInstaller 或 py2exe 等工具以及 Python 编写的插件结合起来没有问题。创建的 .EXE 可以轻松检测它的安装位置,然后里面的代码可以简单地从一些预先确定的插件目录
导入
文件。不要忘记,一旦将 Python 脚本打包成可执行文件,它也会将 Python 解释器打包在里面,这样您就拥有了一个用您自己的代码定制的完整 Python 环境。I think there's no problem combining .EXE packaging with a tool like PyInstaller or py2exe and Python-written plugins. The created .EXE can easily detect where it's installed and the code inside can then simply
import
files from some pre-determined plugin directory. Don't forget that once you package a Python script into an executable, it also packages the Python interpreter inside, so there you have it - a full Python environment customized with your own code.