Search code examples
pythonoptimizationpyinstallerexecutable

python to executable size optimization


I'm going to build python to executable but the size is big(about 6 MB). I'd like to reduce size less than 4 MB.

Let me know how to optimize that. Thanks.

from requests import get, post
from sseclient import SSEClient
import time
import subprocess

#set server url
server_uri = 'http://127.0.0.1/server.php'
try:
    my_id = get('https://api.ipify.org').text

    try:
        server = get(server_uri)
        print(server.headers)

        messages = SSEClient(server_uri)
        subprocess.call('ipconfig', shell=True) 

    except Exception as e:
        print("you can't connect to server\n")

except Exception as e:
    print("Please check your internet connection\n")

Let me know how to optimize that.


Solution

  • If you are using pyinstaller to create executable, check if you have virtual env. created and only required modules are installed . in some cases all modules are packaged if not dedicated virtual env is created for project .