SoFunction
Updated on 2024-11-15

Solve the problem of missing plotly libraries when pyinstaller packages and runs the program.

I packaged the tkinter program with pyinstaller, and ran the exe after packaging, but it reported the following error:

I searched for a while and found out that pyinstaller might miss some of the tertiary libraries when packaging (the main program file I want to package), so I added the absolute paths of the tertiary libraries when packaging:

pyinstaller  -F -p C:\Python36\Lib\site-packages

Found that after packaging still report the above problem, after continuing to search with the addition of hook file can be solved (completely solved my problem), modify the method:

1. Find C:\Python36\Lib\site-packages\PyInstaller\hooks, which looks like this:

2. You need to create a new similar file here with the following contents:

from  import collect_data_files
 
datas = collect_data_files('plotly')

3. and then repackaged, packaged when it is important to remember to remove the same level of directory files (in the packaging will be automatically generated, if not deleted before the unsuccessful content is still cached in the), the packaging process will see the addition of the plotly library:

Common commands for pyinstaller packaging:

-F Specifies that only one exe file will be generated after packing.
-D -onedir creates a directory that contains exe files, but will depend on many files (default option)
-c -console, -nowindowed Use console, no interface (default)
-w -windowed, -noconsole Use window, no console

-i Changing the icon icon of the generated program

Problems with pyinstaller not working properly after packing plotly

After using pyinstaller to package a program with plotly, the following feedback occurs when running the program

"c:\users*\appdata\local\continuum\anaconda3\envs\py34\lib\site-p ackages\PyInstaller\loader\pyimod03_importers.py", line 474, in get_data
with open(path, 'rb') as fp:
FileNotFoundError: [Errno 2] No such file or directory:
 'H:\Python\Commodity_M AI_Trade_List\Code\dist\comdty_runtime\plotly\package_data\default-schema. json'
 Failed to execute script comdty_runtime

This is caused by the fact that pyinstaller is not compatible with plotly right now, the solution is as follows:
1. Do not choose to use -F to pack into a single file when packaging
2. After packaging, copy the plotly folder from the anaconda directory (the author's location is E:Anaconda3\Lib\site-packages\plotly) to the packaged folder (the author's location is D:\Anaconda Library\XXXX project\dist{exe name folder}\).

After copying, you can use the exe file without any problem.

to this article on the solution pyinstaller package to run the program when there is a lack of plotly library problem is introduced to this article, more related to pyinstaller package to run plotly error content please search my previous posts or continue to browse the following related articles I hope that you will support me more in the future!