Anaconda PIL/枕头-值错误:未设置py.\uuuu规格
我正在尝试使用py2exe创建一个exe文件。在此之前,这是很好的-我仍然有我编辑的代码的工作exe文件。但是,当我现在尝试运行下面的代码时,在Anaconda命令提示符中出现了“ValueError:py.\uu spec\uu未设置”错误。尝试创建另一个程序的exe文件的结果是正确的 不幸的是,我保存了以前运行过的旧版本的程序,但我将新程序从内存恢复到旧版本,它仍然无法运行。知道为什么会这样吗?我相信这与PIL模块有关,因为这是我的其他程序继续正确转换为exe的唯一区别。此外,注释掉PIL模块也会导致成功转换。但是,这意味着该程序不能用于它所制作的内容 py2exe setup.py代码:Anaconda PIL/枕头-值错误:未设置py.\uuuu规格,anaconda,python-imaging-library,python-3.8,py2exe,valueerror,Anaconda,Python Imaging Library,Python 3.8,Py2exe,Valueerror,我正在尝试使用py2exe创建一个exe文件。在此之前,这是很好的-我仍然有我编辑的代码的工作exe文件。但是,当我现在尝试运行下面的代码时,在Anaconda命令提示符中出现了“ValueError:py.\uu spec\uu未设置”错误。尝试创建另一个程序的exe文件的结果是正确的 不幸的是,我保存了以前运行过的旧版本的程序,但我将新程序从内存恢复到旧版本,它仍然无法运行。知道为什么会这样吗?我相信这与PIL模块有关,因为这是我的其他程序继续正确转换为exe的唯一区别。此外,注释掉PIL模
from distutils.core import setup
import py2exe
setup(console=['resizeImg.py'])
from PIL import Image
import os, sys
from pathlib import Path
while True:
# Warning message for users
print('')
print('IMPORTANT!!!'.center(len('IMPORTANT!!!')+12,'*'))
print('If a file exists in the same name in destination folder, \
it will be IRREVERSIBLY OVERWRITTEN!')
print('*'*(len('IMPORTANT!!!')+12))
print('\nEnter full paths for source and destination. \
\nEnter q to quit.')
spath = input('Source path: ')
if spath == 'q':
sys.exit()
dpath = input('Destination path: ')
if dpath == 'q':
sys.exit()
elif dpath == spath:
Path(spath,'scaledImages').mkdir(exist_ok=True)
dpath = str(Path(spath,'scaledImages'))
htsize = int(input('Height dimension: '))
if htsize == 'q':
sys.exit()
os.chdir(Path(spath))
optSize = htsize
for filename in os.listdir('.'):
print (filename)
if not (filename.endswith('.jpeg') or filename.endswith('.jpg') or filename.endswith('.png') or filename.endswith('.bmp')):
continue
else:
im = Image.open(filename)
width, height = im.size
if height > optSize:
# commented out to remove width height check
# if width > height:
# height = int((optSize / width) * height)
# width = optSize
# else:
# width = int((optSize / height) * width)
# height = optSize
width = int((optSize / height) * width)
height = optSize
print('')
print(f'Resizing {filename} ...')
im = im.resize((width,height))
im.save(Path(dpath) / filename)
else:
im.save(Path(dpath) / filename)
print('New dimension: ' + str(width) + ' x ' + str(height))
print('\nRescaling complete. Rescaled images saved in: ' + \
dpath + '\n')
quitPrompt = input('q to quit; any other input for new search: ')
if quitPrompt.lower() == 'q':
sys.exit()
我的节目:
from distutils.core import setup
import py2exe
setup(console=['resizeImg.py'])
from PIL import Image
import os, sys
from pathlib import Path
while True:
# Warning message for users
print('')
print('IMPORTANT!!!'.center(len('IMPORTANT!!!')+12,'*'))
print('If a file exists in the same name in destination folder, \
it will be IRREVERSIBLY OVERWRITTEN!')
print('*'*(len('IMPORTANT!!!')+12))
print('\nEnter full paths for source and destination. \
\nEnter q to quit.')
spath = input('Source path: ')
if spath == 'q':
sys.exit()
dpath = input('Destination path: ')
if dpath == 'q':
sys.exit()
elif dpath == spath:
Path(spath,'scaledImages').mkdir(exist_ok=True)
dpath = str(Path(spath,'scaledImages'))
htsize = int(input('Height dimension: '))
if htsize == 'q':
sys.exit()
os.chdir(Path(spath))
optSize = htsize
for filename in os.listdir('.'):
print (filename)
if not (filename.endswith('.jpeg') or filename.endswith('.jpg') or filename.endswith('.png') or filename.endswith('.bmp')):
continue
else:
im = Image.open(filename)
width, height = im.size
if height > optSize:
# commented out to remove width height check
# if width > height:
# height = int((optSize / width) * height)
# width = optSize
# else:
# width = int((optSize / height) * width)
# height = optSize
width = int((optSize / height) * width)
height = optSize
print('')
print(f'Resizing {filename} ...')
im = im.resize((width,height))
im.save(Path(dpath) / filename)
else:
im.save(Path(dpath) / filename)
print('New dimension: ' + str(width) + ' x ' + str(height))
print('\nRescaling complete. Rescaled images saved in: ' + \
dpath + '\n')
quitPrompt = input('q to quit; any other input for new search: ')
if quitPrompt.lower() == 'q':
sys.exit()
当我试图通过运行“python setup.py py2exe”在Anaconda命令提示符下执行py2exe时
运行py2exe
回溯(最近一次呼叫最后一次):
文件“setup.py”,第11行,在
设置(控制台=['resizeImg.py'])
文件“C:\Users\hamis\anaconda3\lib\distutils\core.py”,第148行,在安装程序中
dist.run_命令()
文件“C:\Users\hamis\anaconda3\lib\distutils\dist.py”,第966行,在run\u命令中
self.run_命令(cmd)
文件“C:\Users\hamis\anaconda3\lib\distutils\dist.py”,第985行,在run\u命令中
cmd_obj.run()
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\distutils\u buildexe.py”,第192行,正在运行
self._run()
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\distutils\u buildexe.py”,第272行,正在运行
builder.analyze()
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\runtime.py”,第177行,在analyze中
目标分析(mf)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\runtime.py”,第78行,在analyze中
modulefinder.run_脚本(self.script)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第62行,在运行脚本中
自我扫描代码(模块代码,模块)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第386行,在扫描代码中
self.safe\u import\u hook(名称、mod、fromlist、级别)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第122行,在safe\u import\u hook中
self.import\u钩子(名称、调用方、fromlist、级别)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第109行,在导入钩子中
self.\u handle\u fromlist(模块、fromlist、调用者)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第180行,在\u handle\u fromlist中
self._gcd_import(“{}.{}.”格式(mod.u name_uu,x))
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第258行,在\u gcd\u import中
返回自我。查找并加载(名称)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第348行,在查找和加载中
自我扫描代码(模块代码,模块)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第393行,在扫描代码中
自我扫描代码(c、mod)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第393行,在扫描代码中
自我扫描代码(c、mod)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第386行,在扫描代码中
self.safe\u import\u hook(名称、mod、fromlist、级别)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第122行,在safe\u import\u hook中
self.import\u钩子(名称、调用方、fromlist、级别)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第109行,在导入钩子中
self.\u handle\u fromlist(模块、fromlist、调用者)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第180行,在\u handle\u fromlist中
self._gcd_import(“{}.{}.”格式(mod.u name_uu,x))
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第258行,在\u gcd\u import中
返回自我。查找并加载(名称)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第348行,在查找和加载中
自我扫描代码(模块代码,模块)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第393行,在扫描代码中
自我扫描代码(c、mod)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第393行,在扫描代码中
自我扫描代码(c、mod)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第386行,在扫描代码中
self.safe\u import\u hook(名称、mod、fromlist、级别)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第122行,在safe\u import\u hook中
self.import\u钩子(名称、调用方、fromlist、级别)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第104行,在导入钩子中
模块=self.\u gcd\u导入(名称)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第258行,在\u gcd\u import中
返回自我。查找并加载(名称)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第348行,在查找和加载中
自我扫描代码(模块代码,模块)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第386行,在扫描代码中
self.safe\u import\u hook(名称、mod、fromlist、级别)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第122行,在safe\u import\u hook中
self.import\u钩子(名称、调用方、fromlist、级别)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第109行,在导入钩子中
self.\u handle\u fromlist(模块、fromlist、调用者)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第180行,在\u handle\u fromlist中
self._gcd_import(“{}.{}.”格式(mod.u name_uu,x))
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第258行,在\u gcd\u import中
返回自我。查找并加载(名称)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第348行,在查找和加载中
自我扫描代码(模块代码,模块)
文件“C:\Users\hamis\anaconda3\lib\site packages\py2exe\mf34.py”,第386行,在扫描代码中
自我安全
ValueError: py.__spec__ is not set
from distutils.core import setup
import py2exe
setup(options = {"py2exe":{ "excludes": ["_pytest","qtpy"] } },
console = ['resizeImg.py'])