Created .exe cannot be opened when moved to a new directory

1,936 views
Skip to first unread message

Paul Fishback

unread,
Feb 6, 2022, 12:01:49 PM2/6/22
to PyInstaller
My computer is a Mac running OS 11.6.1 and I've created a Windows 10 virtual machine with VMware Fusion. 

I've had no problems creating an .app with pyinstaller on the Mac side. I can move it to a new directory and double-click to open it.

One the Windows side, I can run pyinstaller.exe fine using a "bare-bones" .spec file, where I've only attempted to change the icon. The .exe was located in a folder (having the program name) which in turn was located in dist. The original .py and .spec were located in  C:\Users\MyName\Desktop

Unfortunately the .exe cannot be opened when I move it to a new directory on my virtual machine. Double clicking it results in a fatal error message, 

"Error loading Python DLL '\\vmware -host\Shared Folders\Desktop\python39.dll '. LoadLibrary: The specified module could not be found. 

I'm pretty sure I'm missing something in terms of how a virtual machine works and would appreciate insights into what I'm doing wrong. 

Thanks

PaulF

bwoodsend

unread,
Feb 7, 2022, 3:12:23 AM2/7/22
to PyInstaller

You’ve built in onedir mode (the default) which as the name suggests produces a directory. The EXE file inside that directory will not function without the rest of the contents of that folder. You need to distribute the folder with the program name. Or build in --onefile mode.

Paul Fishback

unread,
Feb 7, 2022, 10:48:55 AM2/7/22
to PyInstaller
So, following the steps at https://pyinstaller.readthedocs.io/en/stable/spec-files.html, I could add the run time option -F,--onefile in my spec file by defining

options=[('F' ,None,'OPTION')]

and including this as a parameter of my EXE instance, e.g. 

exe = EXE(pyz,
          a.scripts,
          [],
          options,...)


This didn't change the outcome, so I'm still missing something.

Thanks

Eric Fahlgren

unread,
Feb 8, 2022, 3:47:54 AM2/8/22
to pyins...@googlegroups.com
On Mon, Feb 7, 2022 at 7:48 AM Paul Fishback <fishba...@gmail.com> wrote:
So, following the steps at https://pyinstaller.readthedocs.io/en/stable/spec-files.html, I could add the run time option -F,--onefile in my spec file by defining

options=[('F' ,None,'OPTION')]

and including this as a parameter of my EXE instance, e.g. 

exe = EXE(pyz,
          a.scripts,
          [],
          options,...)

I believe that 'options' is for Python runtime, not for PyInstaller command line.  You need to generate a .spec file that aggregates the binaries into the EXE phase.   The easiest way to do that is

> pyinstaller --onefile myscript.py

and then use the 'myscript.spec' as the basis for any further modifications.  Once you have the .spec file, then feed it to pyinstaller, instead of the script.

> pyinstaller myscript.spec

Paul Fishback

unread,
Feb 8, 2022, 3:48:01 AM2/8/22
to PyInstaller
I believe I figured things out. Adding 'F' as an option via setting options=[('F' ,None,'OPTION')] in my previous attempt won't work since the only options that can be included in the bundled app in such a manner are v, u, W. 

Is that correct?

Instead I simply ran my_app.spec --onefile at the command line, which worked. 

Thanks

Paul 

Paul Fishback

unread,
Feb 8, 2022, 11:26:53 AM2/8/22
to pyins...@googlegroups.com, Paul Fishback
Thanks. Yes, my usual approach has been to first create the .spec file and then modify it as needed. Here's a summary of what I tried using a script, hello_world.py, which creates a simple tkinter gui with a close button. 

1. pyinstaller hello_world.py --one file. 
This works fine of course--the dist folder contains a single executable.

2. pyinstaller hello_world.spec
Now the dist folder contains a folder, hello_world, not a single executable. This isn't what I want.

3. pyinstaller hello_world.spec --one file.
Same outcome as (2)

In my more complicated application, I'll need to modify the spec file to include numerous data files, specify hidden imports, and add an icon. So the ultimate question is how do I modify the spec file so that dist contains a single executable? In other words, what modification to the spec file accomplishes the same thing as using the command line option --onefile?



--
You received this message because you are subscribed to a topic in the Google Groups "PyInstaller" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyinstaller/1D5iK9Uv2TE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/CAP2Qz%2BVW67vrO25M52ubqT9y5DmaEUFX1txwW5fEnAnfZEsmEg%40mail.gmail.com.

Eric Fahlgren

unread,
Feb 8, 2022, 11:49:34 AM2/8/22
to pyins...@googlegroups.com, Paul Fishback
You need to move all of the binaries, zipfiles and datas into the EXE, make sure exclude_binaries is False, and delete the COLLECT.

image.png



You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/CACWiRmn_HGQPmQpg19dTvGu0dPeC3n3uFZ%2BdwAsXseJT52Nb%3Dg%40mail.gmail.com.

bwoodsend

unread,
Feb 10, 2022, 11:00:02 AM2/10/22
to PyInstaller

I’m afraid that there’s no nice switch in the spec file to toggle between onefile and onedir mode. Converting spec files is possible but you’d be better just creating a new spec file. And for the record, pyinstaller program.spec ignores --onefile (and almost all other flags).

Reply all
Reply to author
Forward
0 new messages