python: Can I run a python script without actually installing python?

Question:

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)?

Asked By: ccwhite1

||

Answers:

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

Answered By: Tim Pietzcker

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.

Answered By: ccwhite1

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

Answered By: nitrogenycs

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.

Answered By: TheGerm

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?

Answered By: Alexis MARTIN

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.

Answered By: Frank