Install Python 2.6 without using installer on Win32
Asked Answered
M

6

20

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.

  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?

Micronutrient answered 20/4, 2010 at 21:16 Comment(4)
Beware of manually installing Python. You will probably get it to run just fine but installing any additional libraries is a major pain in the posterior.Crotch
can you just package your app using py2exe? (it will include a copy of the interpreter inside an exe)Notability
How would Python find the zip if the name were not hardcoded? But more importantly, why do you need to change it?Omission
I'm trying to do the same, but I'm stuck on step 1. How do you copy Microsoft.VC90.CRT.manifest?Somersault
M
11

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.

Micronutrient answered 21/4, 2010 at 16:11 Comment(0)
C
26

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.

Cadge answered 20/4, 2010 at 21:20 Comment(7)
Hadn't heard of PortablePython before. Great tip.Danelle
you can add additional modules to the USB containing PP, so theres nothing stopping you from using that over the copying you're doing nowCondescending
ummmm users can be quite oblivous to what's going on around them but wouldn't they notice the USB drive?Babita
why is this not the accepted solution ? this totally solved my problem.Stripy
"Portable Python is not being developed anymore"Muth
Note there's a 2.7.3.1 version alsoOkechuku
@das_weezu, How does this differ from py2exe?Institutor
C
19

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

Cameleer answered 24/7, 2015 at 7:44 Comment(1)
I had to do similar recently with 2.7.11. Also, you will have to install pip manually (using the get-pip.py script).Positron
M
11

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.

Micronutrient answered 21/4, 2010 at 16:11 Comment(0)
P
6

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.

Physiography answered 13/10, 2014 at 15:15 Comment(0)
L
3

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.

Leukas answered 21/4, 2010 at 0:11 Comment(0)
T
3

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.

Topdrawer answered 21/4, 2010 at 7:29 Comment(1)
PyInstaller doesn't support Windows with Python2.6. It's a blocker for me and may be for others too. pyinstaller.org/wiki/Python26WinRepugnance

© 2022 - 2024 — McMap. All rights reserved.