开发者

Install Python 2.6 without using installer on Win32

开发者 https://www.devze.com 2022-12-27 19:15 出处:网络
I need to run a Python script on a machine that doesn\'t have Python installed. I use Python as a part of a software package, and Python runs behind the curtain without the user\'s notice of it.

I need to run a Python script on a machine that doesn't have Python installed. I use Python as a part of a software package, and Python runs behind the curtain without the user's notice of it.

What I did was as follows.

    开发者_JAVA百科
  1. Copy python.exe, python26.dll, msvcr90.dll and Microsoft.VC90.CRT.manifest
  2. Zip all the directory in LIBs directory as the python26.zip
  3. Copy all the necessary dll/pyd files inside the DLL directory.

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.

  • Question 1: What's the magic behind the python26.zip name? Python automatically finds a library inside a python26.zip, but not with different name?
  • 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). Is it correct?

Python has built-in libraries, and sys is one of them. I thought that I could use sys.path to point to whatever Python library in the ZIP file I needed. But, surprisingly, if I use the library name as Python26.zip, it just worked. 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.

There is a Python 2.5.4, 2.6.1 and a 3.0.1 version.


From Sylvain Pointeau's blog:

The procedure is actually very simple, just download the msi installer from http://www.python.org/getit/ and type the command:

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. 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. Just extract to a tempdir and then cleanup when they uninstall it.

PS: I didn't see how old this was! :D


I looked into the Python interpreter source code, and I did some experiments. And I found that the Python interpreter prepend the "THE DIRECTORY OF PYTHONXXX.DLL + pythonXXX.zip" no matter what. XXX is the version of the Python interpreter.

As a result, if there is a python26.zip in the same directory as the python26.dll. I could use all of the Python library automatically.


Another option is installing WinPython. It uses an installer, but it doesn't require admin rights (tested on Windows 7). Unlike Portable Python, it even has a Python 3.3.5 version.


py2exe will allow you to compile your Python script into a Windows executable. 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.


Another option might be to consider PyInstaller which will create stand-alone Python applications cross-platform. 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. 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. You'll never be required to look for tricks in wikis and apply custom modification to your files or your setup scripts. As an example, libraries like PyQt and Matplotlib are fully supported, without having to handle plugins or external data files manually. Check our compatibility list of SupportedPackages.

0

精彩评论

暂无评论...
验证码 换一张
取 消