0

I converted a file, main.py, into main.exe, using PyInstaller. main.py doesn't throw any error, but main.exe does.

The script didn't execute fully, so I used a try-catch and got this:

Cannot copy tree 'Y': not a directory

It looks like it's a problem with how I converted it into an EXE with PyInstaller.

This is the PyInstaller command I used to convert it into an EXE:

pyinstaller --onefile --windowed --icon "X/logo.ico"
--name "H" --add-data "X/Y;Y/" --add-data 
"X/dmode.png;." --add-data "X/lu.png;." --add-data "X/toggle.png;." 
--add-data "X/white.png;." --paths "C:/Users/Username/venv/Lib/site-packages" 
--hidden-import "tkinter" --hidden-import "os" --hidden-import "sys" 
--hidden-import "distutils" --hidden-import "shutil" 
--hidden-import "win32gui"  "X/main.py"

And this is the file structure:

X

  • build, dist and other folders created by PyInstaller and PyCharm (IDE)

  • Y

    • JS
      • cS.js
    • i.jpeg
    • M.json
  • Z (the directory in which Y will be copied)

  • dmode.png

  • logo.ico

  • lu.png

  • main.py

  • toggle.png

  • white.png

X is the directory in which main.py is. This is apparently the code which causes the error:

from os.path import join
from distutils.dir_util import copy_tree

if getattr(sys, 'frozen', False):
    application_path = os.path.dirname(sys.executable)
elif __file__:
    application_path = os.path.dirname(__file__)

if not os.path.exists(join(application_path, "Z")):
    copy_tree("Y", join(application_path, "Z"))

But I don't get any errors when I run the PyInstaller command in CMD. So, where have I gone wrong? Have I used --add-data incorrectly? Is application_path wrong (copied from this)? If yes, please mention where I've used it incorrectly and where I have referenced the files/directories incorrectly. I prefer changing the command instead of the .spec file, so a PyInstaller (CMD) command would be helpful.

The Amateur Coder
  • 789
  • 3
  • 11
  • 33
  • please post the error message you are receiving. – Alexander Apr 11 '23 at 06:12
  • @Alexander, "Cannot copy tree 'Y': not a directory" is all I get. I've tried many other ways, like changing all the destinations to `.` and then rewriting the file references, but I get `PermissionError`s ('Permission Denied'; though I used `--uac-admin` and have given permissions via File Explorer, even when I run it as administrator), or it just doesn't copy. It simply doesn't copy the files (the code to copy runs). I'll edit my question to include what else I've tried. – The Amateur Coder Apr 11 '23 at 13:43

0 Answers0