简体   繁体   English

在Win32上不使用安装程序安装Python 2.6

[英]Install Python 2.6 without using installer on Win32

I need to run a Python script on a machine that doesn't have Python installed. 我需要在没有安装Python的机器上运行Python脚本。 I use Python as a part of a software package, and Python runs behind the curtain without the user's notice of it. 我使用Python作为软件包的一部分,并且Python在幕后操作而没有用户注意到它。

What I did was as follows. 我做的如下。

  1. Copy python.exe, python26.dll, msvcr90.dll and Microsoft.VC90.CRT.manifest 复制python.exe,python26.dll,msvcr90.dll和Microsoft.VC90.CRT.manifest
  2. Zip all the directory in LIBs directory as the python26.zip 将LIBs目录中的所有目录压缩为python26.zip
  3. Copy all the necessary dll/pyd files inside the DLL directory. 将所有必需的dll / pyd文件复制到DLL目录中。

It seems to work, but when I change the python26.zip to the other name such as pythonlib.zip, it cannot find the Python library any more. 它似乎工作,但当我将python26.zip更改为pythonlib.zip等其他名称时,它再也找不到Python库了。

  • Question 1: What's the magic behind the python26.zip name? 问题1:python26.zip名称背后的魔力是什么? Python automatically finds a library inside a python26.zip, but not with different name? Python自动在python26.zip中找到一个库,但不是用不同的名字?
  • Question 2: If I have python26.zip at the same directory where python.exe/python26.dll is, I don't need to add path sys.path.append (THE PATH TO python26.zip). 问题2:如果我在python.exe / python26.dll所在的同一目录下有python26.zip,我不需要添加路径sys.path.append (THE PATH TO python26.zip)。 Is it correct? 这是对的吗?

Python has built-in libraries, and sys is one of them. Python有内置库, sys就是其中之一。 I thought that I could use sys.path to point to whatever Python library in the ZIP file I needed. 我以为我可以使用sys.path指向我需要的ZIP文件中的任何Python库。 But, surprisingly, if I use the library name as Python26.zip, it just worked. 但是,令人惊讶的是,如果我将库名称用作Python26.zip,它就可以了。 Why is this so? 为什么会这样?

I have been using PortablePython for a year now, and I find it great as it is working on my locked-down work-notebook. 我已经使用PortablePython一年了,我发现它很棒,因为它正在我的锁定工作笔记本上工作。

There is a Python 2.5.4, 2.6.1 and a 3.0.1 version. 有一个Python 2.5.4,2.6.1和3.0.1版本。

From Sylvain Pointeau's blog : 来自Sylvain Pointeau的博客

The procedure is actually very simple, just download the msi installer from http://www.python.org/getit/ and type the command: 该过程实际上非常简单,只需从http://www.python.org/getit/下载msi安装程序并输入命令:

C:\\development\\apps>msiexec /a python-3.3.2.msi /qb TARGETDIR=C:\\development\\apps\\python33

His example uses msiexec (aka MSI Administrative Installer for you UniExtract people) to force an extract to TARGETDIR . 他的例子使用msiexec(也就是你的UniExtract人的MSI管理安装程序)强制提取到TARGETDIR You'll notice that there is an internal installer which you delete. 你会发现, 你删除一个内部安装程序。

EDIT: Also you can make it silent as well, but doing this every time you want to use python seems dumb. 编辑:你也可以让它沉默,但每次你想使用python这样做似乎是愚蠢的。 Just extract to a tempdir and then cleanup when they uninstall it. 只需解压缩到tempdir然后在卸载时清理它们。

PS: I didn't see how old this was! PS:我没看到这多大了! :D :d

I looked into the Python interpreter source code, and I did some experiments. 我查看了Python解释器源代码,并做了一些实验。 And I found that the Python interpreter prepend the "THE DIRECTORY OF PYTHONXXX.DLL + pythonXXX.zip" no matter what. 而且我发现Python解释器无论如何都会在“PYTHONXXX.DLL + pythonXXX.zip的目录”前面加上。 XXX is the version of the Python interpreter. XXX是Python解释器的版本。

As a result, if there is a python26.zip in the same directory as the python26.dll. 因此,如果python26.zip与python26.dll在同一目录中。 I could use all of the Python library automatically. 我可以自动使用所有的Python库。

Another option is installing WinPython . 另一种选择是安装WinPython It uses an installer, but it doesn't require admin rights (tested on Windows 7). 它使用安装程序,但不需要管理员权限(在Windows 7上测试)。 Unlike Portable Python, it even has a Python 3.3.5 version. 与Portable Python不同,它甚至还有Python 3.3.5版本。

Another option might be to consider PyInstaller which will create stand-alone Python applications cross-platform. 另一个选择可能是考虑PyInstaller ,它将创建跨平台的独立Python应用程序。 From the home page: 从主页:

PyInstaller is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, and Mac OS X. [...] The main goal of PyInstaller is to be compatible with 3rd-party packages out-of-the-box. PyInstaller是一个程序,可以在Windows,Linux和Mac OS X下将Python程序转换(打包)成独立的可执行文件。[...] PyInstaller的主要目标是与第三方软件包兼容。开箱。 This means that, with PyInstaller, all the required tricks to make external packages work are already integrated within PyInstaller itself so that there is no user intervention required. 这意味着,使用PyInstaller,使外部包工作所需的所有技巧已经集成在PyInstaller本身中,因此不需要用户干预。 You'll never be required to look for tricks in wikis and apply custom modification to your files or your setup scripts. 您永远不会被要求在wiki中查找技巧并对您的文件或设置脚本应用自定义修改。 As an example, libraries like PyQt and Matplotlib are fully supported, without having to handle plugins or external data files manually. 例如,完全支持像PyQt和Matplotlib这样的库,而无需手动处理插件或外部数据文件。 Check our compatibility list of SupportedPackages. 查看我们的SupportedPackages兼容性列表。

py2exe will allow you to compile your Python script into a Windows executable. py2exe将允许您将Python脚本编译为Windows可执行文件。 It may or may not work better than PortablePython, but perhaps it could be a little cleaner with regard to the number of files you need to distribute for your "behind the curtain" program. 它可能会或可能不会比PortablePython更好地工作,但是对于你需要为“幕后”程序分发的文件数量,它可能会更清晰一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM