如何将 Python 部署到 Windows 用户?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1646326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to deploy Python to Windows users?
提问by mamcx
I'm soon to launch a beta appand this have the option to create custom integration scripts on Python.
我很快就会推出一个测试版应用程序,它可以选择在Python上创建自定义集成脚本。
The app will target Mac OS Xand Windows, and my problem is with Windows where Python normally is not present.
该应用程序将针对Mac OS X和 Windows,而我的问题是在通常不存在 Python 的 Windows 上。
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...
我的实际方法是静默运行 Python 2.6 安装。但是我遇到了默认情况下未激活的问题,并且在使用命令行选项时未设置路径。而且我担心如果之前安装了 Python 并且我升级到新版本,这可能会破坏其他东西......
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?).
所以,我想知道如何干净利落地做到这一点。如果我复制整个 Python 2.6 目录,并将其放在我的应用程序的子目录中并在那里安装所有内容,是否可以?或者使用 virtualenv 可以运行不同版本的 Python(如果 Python 已经安装在机器中?)。
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.
之前也玩过把Python嵌入DLL,觉得很简单,但是没办法调试,所以改用命令行插件了。
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.
我从命令行执行插件并读取 STDOUT 和 STDERR 输出。该应用程序是用 Delphi/Lazarus 制作的。我安装了其他模块,如 JSON 和 RPC 客户端、Win32com、ORM 等。我使用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.
更新:最终用户是小企业主,Python 脚本由开发人员制作。我想避免部署中的任何额外步骤,所以我想要一个完全集成的设置。
采纳答案by Caleb Hattingh
Copy a Portable Pythonfolder out of your installer, into the same folder as your Delphi/Lazarus app. Set all paths appropriately for that.
从安装程序中复制一个便携式 Python文件夹到与 Delphi/Lazarus 应用程序相同的文件夹中。为此适当设置所有路径。
回答by Jason Baker
回答by Caleb Hattingh
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.
使用P4D将 python 解释器集成到您的 Delphi 应用程序中。这些组件实际上是有效的,并且也是双向的(Delphi 类作为二进制扩展暴露给 Python,Delphi 中的 Python 解释器)。我还在 Google 代码“问题”页面上看到了 Lazarus 兼容性补丁,但似乎那里可能存在一些未解决的问题。
回答by Eli Bendersky
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.
我认为将 .EXE 打包与 PyInstaller 或 py2exe 之类的工具以及 Python 编写的插件相结合是没有问题的。创建的 .EXE 可以很容易地检测到它的安装位置,然后里面的代码可以简单地import
从一些预先确定的插件目录中提取文件。不要忘记,一旦你将 Python 脚本打包成可执行文件,它也会将 Python 解释器打包在里面,这样你就拥有了 - 一个用你自己的代码定制的完整 Python 环境。