Tiny python executable?

I plan to use PyInstaller to create a stand-alone python executable. PythonInstaller comes with built-in support for UPX and uses it to compress the executable but they are still really huge (about 2,7 mb).

Is there any way to create even smaller Python executables? For example using a shrinked python.dll or something similiar?

Asked by: Thomas821 | Posted: 28-01-2022

Answer 1

If you recompile pythonxy.dll, you can omit modules that you don't need. Going by size, stripping off the unicode database and the CJK codes creates the largest code reduction. This, of course, assumes that you don't need these. Remove the modules from the pythoncore project, and also remove them from PC/config.c

Answered by: Sophia904 | Posted: 01-03-2022

Answer 2

Using a earlier Python version will also decrease the size considerably if your really needing a small file size. I don't recommend using a very old version, Python2.3 would be the best option. I got my Python executable size to 700KB's! Also I prefer Py2Exe over Pyinstaller.

Answered by: Luke205 | Posted: 01-03-2022

Answer 3

You can't go too low in size, because you obviously need to bundle the Python interpreter in, and only that takes a considerable amount of space.

I had the same concerns once, and there are two approaches:

  1. Install Python on the computers you want to run on and only distribute the scripts
  2. Install Python in the internal network on some shared drive, and rig the users' PATH to recognize where Python is located. With some installation script / program trickery, users can be completely oblivious to this, and you'll get to distribute minimal applications.

Answered by: Freddie571 | Posted: 01-03-2022

Similar questions

linux - Python 2.6 on Debian Lenny. Where should the executable go?

I am building python2.6 from source on Debian Lenny. ( ./configure make make altinstall ) I don't want it to conflict with anything existing, but I want it to be in the default search path for bash. Suggestions? (ps, I'm using a vm, so I can trash it and rebuild.)

how do you specify which python executable to use in Django 1.1.1?

I have a RH system running RHEL 5.3, which comes with python2.4 that can't be removed for numerous reasons. I have been able to build 64-bit RPMS for python 2.6 as an altinstall. It's called with "python26". How can I tell Django to use this command to get to the proper python version, instead of the default "python". I can, of course, change the symlink in /usr/bin manually, but i'm looking to f...

linux - How to make a call to an executable from Python script?

I need to execute this script from my Python script. Is it possible? The script generate some outputs with some files being written. How do I access these files? I have tried with subprocess call function but without success. fx@fx-ubuntu:~/Documents/projects/foo$ bin/bar -c somefile.xml -d text.txt -r aString -f anotherString >output The application "bar" also references to som...

python - script as module and executable

I have a script in python that can be invoked from the command-line and uses optparse. script -i arg1 -j arg2 In this case I use (options, args) = parser.parse_args() to create options then use options.arg1 to get arguments. But I also want it to be importable as a module. from script import * func...

python - Executable path to Mac App

In a py2app/Mac Application Bundle, is there a way to spawn another instance of same app from within the app, by passing different command line arguments? or given a mac app bundle, how can I run it from command line and pass some arguments too? Edit1:forking is a limited option, which may not work with 3rd party executables bundle with app+I need to run this on mac and windows. Edit2: Question ...

linux - python executable

is it possible to create python executable targeted for linux, from mac os x? PyInstaller seems to be at an early stage, and I don't know much else. Thanks

python - Making my for loop executable

I've created this working for loop in Python: a = 'word' for i in range(len(a)): print a[i:] + a[:i], (a[i:] + a[:i])[::-1] and I need to make it executable from the command line and also have it be able to take in new arguments. I'm a little hazy on how to do this. I know that you need to use if __name__ == '__main__': somehow...And that I n...

python - Remove dock icon for shell executable in Mac OS X?

I know you can remove the dock icon for an app by setting LSUIELEMENT = 1. I have an executable created by cx_freeze, which bundles a set of Python scripts into a single executable. How can I remove the dock icon, with or without using AppleScript?

python - executable files and django

Is it possible to use executable files with Django. For instance I have a Django form that takes input a file. I want to pass the file as an argument to a script/executable/program and output the results back with django. What would be a good starting point for this idea? Thanks a lot

How to make an executable to use in a shell - Python

I have a Python script and I was wondering how I can make it executable; in other words how can I run it by using a shell like bash. I know the first thing is to stick on the first line #! /usr/bin/env python but then do I need for example the functions to be in a specific order (i.e., the main one at the top or the bottom). What's more do I need to keep the extension .py for my python file (can I just...

What do I use on linux to make a python program executable

I just installed a linux system (Kubuntu) and was wondering if there is a program to make python programs executable for linux.

c++ - How to tell whether a file is executable on Windows in Python?

I'm writing grepath utility that finds executables in %PATH% that match a pattern. I need to define whether given filename in the path is executable (emphasis is on command line scripts). Based on "Tell if a ...

python - How do I satisfy a 3rd-party shared library reference to stat when I'm creating a shared library shim rather than an executable?

I am the new maintainer for an in-house Python system that uses a set of 3rd-party shared C libraries via a shared library shim that is created using a combination of swig and a setup.py script. This has been working well until recently. The 3rd-party shared C libraries were updated for new functionality and now I get the following run-time error, after a clean build, when I try to run our main Python program (whic...

executable - Killing the background window when running a .exe from a Python program

the following is a line from a python program that calls the "demo.exe" file. a window for demo.exe opens when it is called, is there any way for demo.exe to run in the "background"? that is, i don't want the window for it show, i just want demo.exe to run. p = subprocess.Popen(args = "demo.exe", stdout = subprocess.PIPE) the output of demo.exe is used by the python program in real tim...

executable - send an arbitrary number of inputs from python to a .exe

p = subprocess.Popen(args = "myprog.exe" + " " + str(input1) + " " + str(input2) + " " + str(input3) + " " + strpoints, stdout = subprocess.PIPE) in the code above, input1, input2, and input3 are all integers that get converted to strings. the variable "strpoints" is a list of arbitrary length of strings. input...

Create an executable process without using shell on Python 2.5 and below

Just what the title says: The subprocess module cannot be used as this should work on 2.4 and 2.5 Shell process should not be spawned to pass arguments. To explain (2), consider the following code: >>> x=os.system('foo arg') sh: foo: not found >>> x=os.popen('foo arg') sh: foo: not found >>> As you can see

linux - Auto executable python file without opening from terminal?

Sorry if this is on the wrong site ( maybe superuser ) but I'm trying to make my python.py file executable so I can click on it and it automatically does its thing, without me specifying it to open in the terminal by that default prompt, and I already have 'chmod +x' for its permissions. Clarification: I want to run it by clicking on it, not through the terminal ( I meant that when I ...

linux - Python 2.6 on Debian Lenny. Where should the executable go?

I am building python2.6 from source on Debian Lenny. ( ./configure make make altinstall ) I don't want it to conflict with anything existing, but I want it to be in the default search path for bash. Suggestions? (ps, I'm using a vm, so I can trash it and rebuild.)

linux - Create single python executable module

Guys, I have much python code in modules which are resides in several python packages and now I need to create single python executable module or file which will include all these files, so it will be working on windows and on linux servers. What are possible solutions and how this can be done?

packaging - Process to convert simple Python script into Windows executable

This question already has answers here:

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python