views:

299

answers:

4

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 the python runs behind the curtain without the user's notice of it.

What I did was as follows.

  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 file 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 anymore.

  • Q1 : What's the magic behind the python26.zip name? The python automatically finds a library inside a python26.zip but not with different name?
  • Q2 : 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?

Added

Python has built in library, and sys is one of them. I thought that I could use sys.path to point to whatever python library in zip file I needed. But, surprisingly, if I use the lib name as Python26.zip, it just worked. I wanted to ask why is this so.

+11  A: 

I'm 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

das_weezul
Hadn't heard of PortablePython before. Great tip.
Frederik
you can add additional modules to the USB containing PP, so theres nothing stopping you from using that over the copying you're doing now
PPTim
ummmm users can be quite oblivous to what's going on around them but wouldn't they notice the USB drive?
John Machin
+1  A: 

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.

What is the name of your app? Link me please :)

pyrony
+1  A: 

Another option might be to consider PyInstaller which will create standalone 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.

ars
PyInstaller doesn't support Windows with Python2.6. It's a blocker for me and may be for others too. http://www.pyinstaller.org/wiki/Python26Win
blokeley
A: 

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

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

Thanks for all the other answers.

prosseek