4

Is there a way to move a my Python program to other computer without the need of re installing all the required module?

Maybe by compilation?

7
  • You mean run it as executable? Commented Aug 24, 2014 at 8:25
  • what do you exactly mean by a module? a compiler? Commented Aug 24, 2014 at 8:25
  • I think what the OP is asking is if there is a way to run a Python program on one computer, and it running in exactly the same way on another computer without having to install Python packages (i.e. running Python code that depends on something like numpy / scipy on one computer, and running the same code on another computer that doesn't have these packages installed, but should still run regardless). Commented Aug 24, 2014 at 8:30
  • 3
    I think that he is talking about packaging all the required python's libraries within the python program. Commented Aug 24, 2014 at 8:31
  • @AlessandroSuglia - That's it. You just said it more eloquently than I did. Commented Aug 24, 2014 at 8:31

4 Answers 4

5

I think you're looking for PyInstaller. By definition, PyInstaller is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, Mac OS X, Solaris and AIX.

PyInstaller as of this writing, doesn't support Python 3. There is however this page on freezing your code or shipping:

Solution    | Windows | Linux | OS X | Python 3 | License | One-file mode | Zipfile import | Eggs | pkg_resources support
bbFreeze    | yes     | yes   |  yes | no       | MIT     | no            | yes            | yes  | yes
py2exe      | yes     | no    | no   | no       | MIT     | yes           | yes            | no   | no
pyInstaller | yes     | yes   | yes  | no       | GPL     | yes           | no             | yes  | no
cx_Freeze   | yes     | yes   | yes  | yes      | PSF     | no            | yes            | yes  | no

See cx_Freeze's documentation here.

Sign up to request clarification or add additional context in comments.

1 Comment

is there python packager that supports python 3.4.1?
1

If you just wanna you python program to run on another computer, PyInstaller or py2exe would be two good recommendations.

PyInstaller supports to several different operating systems: Windows, Linux, Mac OS and so on, while py2exe only supports Windows.

For details, visit:

PyInstaller: http://www.pyinstaller.org/

py2exe: http://www.py2exe.org/

Comments

1

You could execute it with the help of pyinstaller

Install pyinstaller first by -

pip install pyinstaller

Usage -

pyinstaller example.py

This will generate binary in in a subdirectory called build/ & the dependencies will be under dist/ in source folder of your script.

ls -lha build/example/example
ls -lha dist/example/

For manual - https://pyinstaller.readthedocs.io/en/stable/usage.html#running-pyinstaller-with-python-optimizations

Comments

0

You can combine the application and all the pure Python modules that it uses into one zipped file.

Examples of this approach are youtube-dl and my own lamprop program.

Basically, you make a directory that contains directories for all your modules, and your program file, which should be named __main__.py.

> ls
__main__.py  lamprop/
> ls lamprop/
__init__.py html.py latex.py parser.py text.py types.py

This is then wrapped up in a zip-file, and given a shebang-line for use on UNIX-like systems;

cd src; zip -q ../foo.zip __main__.py lamprop/*.py
echo '#!/usr/bin/env python' >lamprop
cat foo.zip >>lamprop
chmod a+x lamprop
rm -f foo.zip

(The commands above are written for use on a UNIX-like system. And on Windows systems the combined file should be given the py extension so that it is handed to the Python interpreter.)

The Python interpreter knows how to handle zipped source code archives. It unpacks them and runs __main__.py.

You could copy installed third-party modules into your source tree and include them in the same way. But there are a couple of things to keep in mind;

  • Licensing: If you want to include third-party modules, their licenses must allow you to do that.
  • Binary modules: some Python libraries like e.g. numpy contain shared libraries that by their nature are platform specific. A numpy module compiled on OS X or Linux will not work on Windows and vice verse.

Comments

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.