1

I have a Script, which using pyinstaller I turned into an Executable.

The issue is I need to be able to run this Script on PC which a) don't have Python installed, and b) no access to internet, and c) the Script used a bunch of packages.

So is there a way in which I can include Pyhton, and the packages into my Executable?

My import statements in my Script look like this:

import os
import datetime
import time
import magic
import json
from dateutil.parser import parse
import sys
import json
import tkinter as tk
from PIL import ImageTk,Image  
from tkinter import *

AND libmagic needs to be installed as well..

Is it possible to include them into my executable?

Nip
  • 45
  • 7

2 Answers2

2

Since you're already using the Pyinstaller package, I'm assuming that the issue is for the packages which aren't imported in the python file as Pyinstaller automatically adds all the imported packages to the executable file. You can use the argument --hidden-import for the packages that you can't or don't want to mention in the file. For example,

pyinstaller --onefile --hidden-import libmagic app.py

See its documentation here.

betelgeuse
  • 1,136
  • 3
  • 13
  • 25
  • Thanks! Does Pyinstaller download Python automatically as well, or do I need to do something for that? – Nip Jun 01 '22 at 10:24
  • Once the executable file is created, it doesn't require anything to be downloaded. It takes care of both Python and the packages. When you run the `pyinstaller` command, make sure you're running it in an environment that has all the packages and right python version installed. For example, create a conda or virtual environment first and install all the required packages with required versions and then run the `pyinstaller` command. – betelgeuse Jun 01 '22 at 10:27
1

Have a look to py2exe, I use this one and I don't have any issues. It works without internet and it transform all your packages.

Create a programm in the same path which the programm you want to transform. Call it setup.py and complete it with :

from distutils.core import setup
import py2exe

setup(console=['yourprogramm.py'])

Don't forget to install the package before pip install py2exe

When your programm is created open a terminal in your programm path with cd command and type :

python setup.py py2exe

You finally get a dist folder and your executable will be in :)

Luc_08
  • 37
  • 6