I am very excited that Pyinstaller exists. I love being able to package an 
app and send it off for anyone without python! But.. to get there, this 
tool is misleadingly complicated..

Before you start.......

"It's very easy, all you do is pyinstaller x.py and you're done, with 
everything included!! Even python and all dependencies!"

False. I had a simple project structure: one main py script, a dir with py 
scripts, and a subdir with some js scripts. I had no idea that I had to 
manually add these files to the spec file! I thought this would be done 
automatically, looking at where I was running the pyinstaller command and 
going recursively. You must add your own files!!!! Spec files are great.. 
way way better than cryptic add-on commands. But the syntax is kinda weird 
too. I'll show you in a bit.. but..

Before you start.. it's cross platform blah blah blah.. WAIT!! Before you 
begin.. it is, but you have to run pysinstaller on a windows machine for 
windows, and pyinstaller on a mac machine for a mac app. You can't do both 
on one OS!

Finally, it's recommended to not do --onefile until you are able to verify 
that all files will be included by just running the regular pyinstaller 
default. >>Pyinstaller will work once you do your share of the job!!<<

"Description: Pyinstaller will package up your python interpreter and any 
import statements it detects, as long as you ADD THE FILES FIRST!! Here's 
how.
1) produce a specfile by running 'pyinstaller yourMainFile.py'
2) edit the specfile as follows:

# add this at the top of the specfile.
# Note:The directory structure starts off the main file. The format would 
be ( 'directory/subdirectory', 'someNameForTheDirectory/subdirectoryName'

added_files = [
    ( 'myDirectory', 'myDirectory' ), #includes all files in the directory, 
keeps the same dir structure
    ( 'tests/exampleFile.xlsx', 'tests' ), #includes a file, and then says 
this file is part of the 'tests' folder in the bundled app.
    ( 'tests/js', 'tests/js' ), # includes another directory
    ]

#THEN.. change this line
   datas=added_files,

# DONE!

3) Make sure you add binaries that may not be included. Like.. 
chromedriver, a VERY common one that isn't included! To find out if the 
binary is not included..

run 'pyinstaller yourMainFile.spec'

You'll notice folders and binaries are included. If your binary is not 
there, you must add it to the spec file like this:

binaries=[('/Users/user/Documents/myApp/driver/chromedriver','driver')],

Then, rerun the pyinstaller command and the app! Test your app and see why 
it failed.

4) Note: some modules may STILL be missing, maybe you need to get them into 
hidden imports, like this:

hiddenimports=['selenium', 'tkinter'],

Finally, we are ready to bundle up the app! Do 'pysinstaller --onefile 
yourMainFile.spec' to have a version you can shoot over to others and run.

- NEXT, here are some gotchas. If you are referencing sys.executable in any 
way, THIS WILL NOT BE THE SAME! Find another way to call a script."
- Possibly --windowed doesn't work? I still get terminal popping up..
- common gotcha no. 2
- common gotcha no. 3
- etc

 GUTTEN LACHT!!

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyinstaller/960c5251-3806-4b10-8355-5466104b39d7%40googlegroups.com.

Reply via email to