我刚刚遇到一个错误,上面写着“没有模块名称socketio”,将它添加到隐藏的导入后我得到“没有模块名称服务器”,并且在添加到隐藏的导入socketio.server之后我得到了新的一个,所以上... 有没有其他方法来添加我的应用程序需要的每个导入?
但是如果我必须这样做,我该如何添加导入: 来自.exceptions导入WebSocketError,因为geventwebsocket.exceptions.WebSocketError不起作用:(
谢谢!
[编辑]这是更多的信息。 我的应用程序可以正常使用PyCharm,在我使用Pyinstaller创建exe后我得到了这个错误,我正在研究添加Pyinstaller没有捕获的导入,我所能找到的就是更改.spec并添加到隐藏 - 导入我的内容需要。 但是我认为添加geventwebsocket就足够了,但正如我所说,现在我得到“无法导入名称WebSocketError”。所以我猜我的代码没问题,因为它在我用Pyinstaller创建exe之前完美运行了吗?
[编辑]这是我的.spec:
# -*- mode: python -*-
a = Analysis(['manage.py'],
pathex=['C:\\Users\\Korisnik\\Downloads\\POSAO\\BioFeedbackServer'],
hiddenimports=['greenlet', 'hid', 'flask_bootstrap',
'flask_socketio', 'blueprints',
'hidapi', 'pywin32', 'xlrd', 'flask_wtf',
'flask_sqlalchemy', 'cython',
'flask_login', 'nexus', 'antiorm', 'colorama',
'socket.error','config', 'cython',
'flask_script', 'init','py', 'requests',
'PyInstaller', 'pyDatalog', 'pytest',
'yaml', 'terminal', 'virtualenv',
'geventwebsocket.server',
'gevent.server', 'socketio', 'socketio.server',
'gevent.pywsgi',
'gevent.baseserver','geventwebsocket.handler',
'socketio.handler',
'geventwebsocket.exceptions.WebSocketError',
'socketio.transports',
'socketio.exceptions.WebSocketError'],
hookspath=None,
runtime_hooks=None)
pyz = PYZ(a.pure)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='manage.exe',
debug=False,
strip=None,
upx=True,
console=True )
dict_tree = Tree('app', prefix = 'app')
dict_tree += Tree('.hg', prefix = '.hg')
dict_tree += Tree('.idea', prefix = '.idea')
coll = COLLECT(exe,
a.binaries,
dict_tree,
a.zipfiles,
a.datas,
strip=None,
upx=True,
name='manage')
错误:
Traceback (most recent call last):
File "<string>", line 7, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py",
line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Korisnik\Downloads\Project\build\manage\out00-PYZ.pyz\app",
line 3, in <module>
File "C:\Users\Korisnik\Downloads\Project\build\manage\out00-P
YZ.pyz\flask.exthook", line 81, in load_module
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line
270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Korisnik\Downloads\Project\build\manage\
out00-PYZ.pyz\flask_socketio", line 5, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py",
line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Korisnik\Downloads\Project\build\manage\
out00-PYZ.pyz\socketio.server", line 8, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py",
line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Korisnik\Downloads\Project\build\manage\
out00-PYZ.pyz\socketio.handler",
line 7, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\
pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Korisnik\Downloads\Project\build\manage\
out00-PYZ.pyz\socketio.transports", line 4, in <module>
ImportError: cannot import name WebSocketError