编程纯小白的我在学习python过程中,尝试使用pyinstaller 打包后的exe一直执行不了,提示Failed to execute script wlcoud,尝试在网上找了很多方法,都解决不了
使用Debug模式抓取失败原因为FileNotFoundError:[Errno 2]No such file or directory.错误截图如下:(其中每次运行exe时找不到的文件的路径下,的._MEI1215402这个文件数字会一直变动)
![7829751460c70c995fbc405ac9fad38b.png](https://i-blog.csdnimg.cn/blog_migrate/cfbf4c6021d860b2b4992d29e6483c0d.jpeg)
执行环境为:python3.6,pyinstaller3.6
![63dfcfbe5505a287a14d2ea8addf1f32.png](https://i-blog.csdnimg.cn/blog_migrate/4637257dfa0b99cc563b68bf8e4bb43b.jpeg)
使用python3.8或者pyinstaller4.0都是这个错误,请教下各位大佬,这个问题应该怎么解决?
代码如下
# 导入相关库
from pandas import Series
from jieba import lcut
from wordcloud import WordCloud
from matplotlib.pyplot import figure,imshow,axis, show
from time import localtime,strftime
from imageio import imread
import configparser
import os
filepath = os.getcwd()
#增加配置文件
def config_parser(cfgpr):
#如果没有配置文件则自动生成
config = configparser.ConfigParser()
if not os.path.exists(os.path.join(filepath,cfgpr)):
config['Sys']={}
config['Sys']['BasicTxt'] = 'test.txt'
config['Sys']['DelTxt'] = 'stoplist.txt'
config['Sys']['BGP'] = 'test.jpg'
config['Sys']['maxword'] = '2000'
config['Sys']['maxfontsize'] = '96'
with open (os.path.join(filepath,cfgpr),'w') as f:
config.write(f)
try:
config_parser(os.path.join(filepath,'config.cfg'))
config = configparser.ConfigParser()
config.read(os.path.join(filepath,'config.cfg'))#读取配置文件,并提取需要的信息
BasicTxt = os.path.join(filepath,config['Sys']['BasicTxt'])
DelTxt = os.path.join(filepath,config['Sys']['DelTxt'])
Bgp = os.path.join(filepath,config['Sys']['Bgp'])
maxword = int(config['Sys']['maxword'])
maxfontsize = int(config['Sys']['maxfontsize'])
# 读取文本文件
with open(BasicTxt,encoding="utf-8") as f:
txt = f.read()
txt = txt.split()
data_cut = [lcut(x) for x in txt]
data_cut
# 读取停用词
with open(DelTxt,encoding="utf-8") as f:
stop = f.read()
stop = stop.split()
stop = [" "] + stop
# 去掉停用词之后的最终词
s_data_cut = Series(data_cut)
all_words_after = s_data_cut.apply(lambda x:[i for i in x if i not in stop])
# 词频统计
all_words = []
for i in all_words_after:
all_words.extend(i)
word_count = Series(all_words).value_counts()
# 词云图的绘制
# 1)读取背景图片
back_picture = imread(Bgp)
# 2)设置词云参数
wc = WordCloud(font_path="simhei.ttf",
background_color="white",
max_words=maxword,
mask=back_picture,
max_font_size=maxfontsize,
random_state=52
)
wc2 = wc.fit_words(word_count)
figure(figsize=(16,8))
imshow(wc2)
axis("off")
show()
wc2.to_file(os.path.join(filepath,"test.png"))
except Exception as e:
a = str(e)
with open(os.path.join(filepath,'faild.txt'),'w') as f:
f.write('[{}] {}'.format(strftime("%Y-%m-%d %H:%M:%S",localtime()),a))