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

6 Answers 6

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.

2
  • Is it possible to pass arguments for the packaged script? using cx_freeze Commented Oct 25, 2017 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. Commented Apr 7, 2018 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

6
  • 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 Commented Apr 4, 2011 at 14:27
  • You mean you need 2.7.1 or 3.1/3.2? I'm sure they are in development already. Commented Apr 4, 2011 at 14:28
  • Yes, for me 2.7.1, but I'll keep watching that site. Thanks Commented Apr 4, 2011 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 Commented Apr 4, 2011 at 14:38
  • The link says that Portable Python isn't being developed anymore. WinPython might be a viable alternative. Commented Oct 26, 2015 at 21:14
7

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

2
  • 2
    Is it possible to pass arguments for the packaged script? using Pyinstaller Commented Oct 25, 2017 at 15:50
  • 1
    @pyd yes, you can use option -c when running pyinstaller --onefile -c myscript.py Commented Jul 31, 2019 at 22:31
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.

1
  • Is it possible to pass arguments for the packaged script? using Winpython Commented Oct 25, 2017 at 15:51
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.

2
  • moving the venv folder does not make it work. you will need to match the distributions, OS etc Commented Oct 9, 2019 at 6:25
  • Well, shoot. I guess I got lucky with it. Commented Oct 10, 2019 at 15:03
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.