Hi All,
I am facing the below issue when using PyInstaller
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: scriptnameI 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)
