Python Forum
[split] Trouble making my first python .exe using pyinstaller.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Trouble making my first python .exe using pyinstaller.
#1
Hi All,

I am facing the below issue when using PyInstaller
Error:
usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME] [--add-data <SRC;DEST or SRC:DEST>] [--add-binary <SRC;DEST or SRC:DEST>] [-p DIR] [--hidden-import MODULENAME] [--additional-hooks-dir HOOKSPATH] [--runtime-hook RUNTIME_HOOKS] [--exclude-module EXCLUDES] [--key KEY] [-d] [-s] [--noupx] [-c] [-w] [-i <FILE.ico or FILE.exe,ID or FILE.icns>] [--version-file FILE] [-m <FILE or XML>] [-r RESOURCE] [--uac-admin] [--uac-uiaccess] [--win-private-assemblies] [--win-no-prefer-redirects] [--osx-bundle-identifier BUNDLE_IDENTIFIER] [--runtime-tmpdir PATH] [--distpath DIR] [--workpath WORKPATH] [-y] [--upx-dir UPX_DIR] [-a] [--clean] [--log-level LEVEL] scriptname [scriptname ...] pyinstaller: error: the following arguments are required: scriptname
I have created a json file to provide the required arguments and a small program to take the data from the json file.
{
	"name": "PythonApp",
	"paths": "",
	"script": "app.py",
	"src_dir": "C:...\\PythonApp",
	"dest_dir": "C:...\\PythonApp\\installation",
	"files": [["core_content/settings.json", "core_content"],
		       ["appConfig.json", "installation"],
		       ["resources.qrc", "installation"]

	],
	"dirs": [["core_content", "core_content"], ["images", "images"], ["log", "log"], ["resources", "resources"], ["ui", "ui"]],


	"cmd": "pyinstaller --onedir --onefile --debug --name={}  --paths=\"{}\" \"{}\""

}
import shutil, errno
import configparser 
import json
import os
import sys
import subprocess



with open("compile.json", "r", encoding="utf-8") as f:
    config = json.load(f)
   
des_dir = config.get("dest_dir")
app_name = config.get("name")
script = config.get("script")
src_dir = config.get("src_dir")
cmd = config.get("cmd")
dirs = config.get("dirs")
files = config.get("files")


if not all([app_name, script, src_dir, des_dir]):
    print("Not all mandatory arguments were given")
    sys.exit(0)
    
if os.path.isdir(des_dir):
    shutil.rmtree(des_dir)
    os.mkdir(des_dir)
os.chdir(des_dir)

script = os.path.join(src_dir, script)

print("Current directory:", os.getcwd())

installer_cmd = cmd.format(app_name, src_dir, script)
print("cmd", installer_cmd)
p = subprocess.Popen(installer_cmd)
p.communicate()


def copy(src, dst):
    try:
        shutil.copytree(src, dst)
    except NotADirectoryError:
        if not os.path.exists(dst):
            os.makedirs(dst)
        shutil.copy(src, dst)


def copy_dirs():
    if not dirs:
        print("No dirs to copy")
    for src, dest in dirs:
        src, dest = os.path.join(src_dir, src), os.path.join(des_dir, "dist", dest)
        copy(src, dest)
    
    
def copy_files():
    if not files:
        print("No files to copy")
    for src, dest in files:
        src, dest = os.path.join(src_dir, src), os.path.join(des_dir, "dist", dest)
        copy(src, dest)

copy_dirs()
copy_files()
shutil.make_archive(app_name, "zip", os.path.join(des_dir, "dist"))


for f in os.listdir("."):
    if f not in (app_name + ".zip"):
        if os.path.isdir(f):
            shutil.rmtree(f)
        elif os.path.isfile(f):
            os.remove(f)
Reply


Messages In This Thread
[split] Trouble making my first python .exe using pyinstaller. - by esha09 - Apr-19-2018, 07:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trouble with installing python domingo251 2 625 Sep-23-2023, 12:03 AM
Last Post: ICanIBB
  Pyinstaller 3 Python 2 mckymntl 0 1,248 Feb-07-2022, 06:28 AM
Last Post: mckymntl
  making variables in my columns and rows in python kronhamilton 2 1,650 Oct-31-2021, 10:38 AM
Last Post: snippsat
  Python 3.7, Windows 10, pyinstaller, winsound, no sound in executable kmarien 3 3,704 Nov-30-2020, 04:10 PM
Last Post: buran
  New to python, having trouble with an exercise Salkay 3 2,200 Feb-18-2020, 01:42 AM
Last Post: Salkay
  Cannot Change Python script to exe using Pyinstaller omar_mohsen 3 2,421 Dec-19-2019, 01:05 PM
Last Post: buran
  More Python Embedding Trouble jibarra 3 2,957 Jul-11-2019, 09:25 PM
Last Post: Gribouillis
  Making a generalised CSV COPY script in Python Sandy7771989 3 2,459 Jul-05-2019, 11:02 PM
Last Post: Larz60+
  [split] I need help making a four digit code cracker with random tycpytyt 1 2,570 Mar-24-2019, 05:53 PM
Last Post: micseydel
  Error with using pyinstaller to convert python script in Mac OS Takeshio 2 5,413 Oct-19-2018, 02:42 PM
Last Post: Takeshio

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020