33

I have some .py files I wrote that I want to run on a different machine. The target machine does not have python installed, and I can't 'install' it by policy. What I can do is copy files over, run my stuff, and then remove them.

What I tried was to just take my development python folder over to the target machine and cd to the python folder and run python.exe /path/to/.py/file. It gave me an error saying that python.dll was not registered. If I registered the DLL that is probably going to move me to far across the 'violating policy' line.

Is there anyway I can accomplish running python files on a machine that does not have python actually installed (trying to get py2exe to work now, but it is painful)?

Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
ccwhite1
  • 3,625
  • 8
  • 36
  • 47

6 Answers6

16

I decided to go with cx_Freeze.

It created a distro that I was able to simply copy and move to the target machine. Also, it was much easier to use than py2exe; further it seems that it is still being maintained (as of Mar 10, 2011), while py2exe development does not look as active.

JIT Solution
  • 693
  • 11
  • 14
ccwhite1
  • 3,625
  • 8
  • 36
  • 47
  • Is it possible to pass arguments for the packaged script? using cx_freeze – Pyd Oct 25 '17 at 15:49
  • As of April 2018 cx_Freeze is still supported. The only issue I had is that the example says to call their custom script (placed in Scripts\) and I had to add a `.py` extension to the file for Windows 7 to recognize and run it. – PfunnyGuy Apr 07 '18 at 15:42
9

Edit: Development of Portable Python has stopped. I will remove this answer shortly.

Check out Portable Python. That should do what you need.

Current versions (as of April 2015) are 2.7.6 and 3.2.5

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
  • 1
    Looks interesting, but possible show stopper that `it supports three versions of Python 2.5.4, 2.6.1 and 3.0.1`. Thanks – eat Apr 04 '11 at 14:27
  • You mean you need 2.7.1 or 3.1/3.2? I'm sure they are in development already. – Tim Pietzcker Apr 04 '11 at 14:28
  • Yes, for me 2.7.1, but I'll keep watching that site. Thanks – eat Apr 04 '11 at 14:34
  • im at 2.7.1 also, so Ill keep an eye on it, but it can't help me now. Also looking at cx_Freeze, but first shot out of the gate had issues – ccwhite1 Apr 04 '11 at 14:38
  • The link says that Portable Python isn't being developed anymore. [WinPython](https://winpython.github.io/) might be a viable alternative. – Frank Oct 26 '15 at 21:14
  • @Frank: Thanks for the suggestion. You should post this as an answer. – Tim Pietzcker Oct 27 '15 at 05:51
7

Check out PyInstaller. It's easier to work with than py2exe (at least for simple applications).

Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
nitrogenycs
  • 962
  • 9
  • 13
1

WinPython might be what you need. It needs to be unpacked using an installer, but the unpacked files can be run out of the box on any machine without any installation.

As of October 2015 it's being actively maintained.

Frank
  • 2,386
  • 17
  • 26
0

This is an old question, but one alternative is creating a virtual environment for Python, which can be as simple as python -m venv myenvname (Python 3.4). You can "install" packages into it the normal way (e.g. pip) without needing anything else. You'll end up with a folder you can move/delete at your leisure.

TheGerm
  • 481
  • 1
  • 4
  • 18
0

It seems virtualenv does not let you easily relocate the virtual environment folder created.

Check virtualenv User Guide. So moving the folder elsewhere may not work. Have you tried the relocate option with virtualenv?