Home > other >  Normal operation of the Python pygal packaged into exe
Normal operation of the Python pygal packaged into exe

Time:09-27

Such as title, made the pygal a simple small program for dice simulation results can generate SVG file
Program running in a compiler, using CMD running. Py files can run normally
But after use pyinstaller packaging error file does not exist, but I did not introduce any software files, why packaged into exe could go wrong?

Later the last generation of SVG in the first file hist. Render_to_file (filename='die. SVG') to delete, then packaged, the generated exe is not an error, need to pack all installed, compiler and operation are normal, directly is not packaged into exe running, why ah, solving!!!!!!
Exe can generate the file after packaging, but nothing written in the file, the empty

On the code and use the CMD error content as follows, please everybody help see





Die_visual. Py files

The import pygal
The from die import die
,6,6 mianshu=[6]
Die_1=Die (mianshu [0])
Die_2=Die (mianshu [1])
Die_3=Die (mianshu [2])
Results=[]

"' storage throwing results" '
Cishu=1000
For roll_num in range (cishu) :
Result=die_1. Roll () + die_2. Roll () + die_3. Roll ()
The append (result)
Frequencies=[]
Max_result=die_1. Num_sides + die_2. Num_sides
For the value in the range (2, max_result + 1) :
# generate tag
Frequency=results. The count (value)
# to calculate each surface occurrences
Frequencies. Append (frequency)
# to join the group tag
# the results are visualized
Hist=pygal. Bar ()
Hist. Title="throwing two six-sided die" + STR (cishu) + "time results statistical
"Biaoqians=[]
, max_result for biaoqian in range (2 + 1) :
Biaoqians. Append (STR (biaoqian))
Hist. X_labels=biaoqians
Hist. X_title="code value"
Hist. Y_title="occurrences"

Hist. Add (" D "+ STR (mianshu [0]) +" + "+" D "+ STR (mianshu [1]), frequencies)
Hist. Render_to_file (filename='die. SVG')


Die. Py files

From the random import randint
The class Die () :
"' a dice class" '
Def __init__ (self, num_sides=6) :
"' dice default six surfaces'
Self. Num_sides=num_sides
Def roll (self) :
'return to random values'
Return randint (1, self. Num_sides)

CodePudding user response:

Reference https://www.jianshu.com/p/fe9ee823501c page "solve the problem of FileNotFoundError" part of the train of thought: the corresponding Python version path "\ Python3p5 \ Lib \ site - packages \ PyInstaller \ hooks" write hook - pygal. Py:
The from PyInstaller. Utils. Hooks import collect_data_files
Datas=collect_data_files (' pygal ')

Can also be reference on the blog https://blog.csdn.net/Hello_liucz/article/details/104714893 have similar problems and solutions,
  • Related