PyInstaller ImportError: cannot import name 'SelectorEventLoop'
PyInstaller ImportError: cannot import name 'SelectorEventLoop'
使用 PyInstaller 在 windows 平台上生成 .exe,运行 .exe 时出现错误:
> (venv) ...>my.exe Traceback (most recent call last): File ".\my.py",
> line 6, in <module> File
> ".\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
> line 631, in exec_module exec(bytecode, module.__dict__) File
> "site-packages\websockets\__init__.py", line 3, in <module> File
> ".\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
> line 631, in exec_module exec(bytecode, module.__dict__) File
> "site-packages\websockets\client.py", line 6, in <module> File
> ".\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
> line 631, in exec_module exec(bytecode, module.__dict__) File
> ".\venv\Lib\site-packages\zmq\asyncio\__init__.py", line 18, in
> <module> ImportError: cannot import name 'SelectorEventLoop' [3696]
> Failed to execute script My
我正在使用 python 3.6.4
和 pyinstaller 3.3
我刚刚将 ayncio 3.4.3
添加到项目中(在此之前一切正常)
欢迎任何想法
经过大量挖掘,我想出了一个解决方案。
问题的来源是:
- 我使用的
zmq
(对于zeromq
)。它嵌入了自己的 asyncio
PyInstaller
修改 sys.path
以添加来自 zeromq
的库。
在我的代码中导入 asyncio
时,它会尝试从 zeromq
导入,但失败了。
我做了一个丑陋的 hack 来解决这个问题。我 post 它可能对某人有帮助
former_path = sys.path[:]
sys.path = [v for v in sys.path if 'zmq' not in v]
import asyncio
sys.path = former_path
到目前为止,我找不到任何副作用
使用 PyInstaller 在 windows 平台上生成 .exe,运行 .exe 时出现错误:
> (venv) ...>my.exe Traceback (most recent call last): File ".\my.py",
> line 6, in <module> File
> ".\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
> line 631, in exec_module exec(bytecode, module.__dict__) File
> "site-packages\websockets\__init__.py", line 3, in <module> File
> ".\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
> line 631, in exec_module exec(bytecode, module.__dict__) File
> "site-packages\websockets\client.py", line 6, in <module> File
> ".\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
> line 631, in exec_module exec(bytecode, module.__dict__) File
> ".\venv\Lib\site-packages\zmq\asyncio\__init__.py", line 18, in
> <module> ImportError: cannot import name 'SelectorEventLoop' [3696]
> Failed to execute script My
我正在使用 python 3.6.4
和 pyinstaller 3.3
我刚刚将 ayncio 3.4.3
添加到项目中(在此之前一切正常)
欢迎任何想法
经过大量挖掘,我想出了一个解决方案。
问题的来源是:
- 我使用的
zmq
(对于zeromq
)。它嵌入了自己的asyncio
PyInstaller
修改sys.path
以添加来自zeromq
的库。
在我的代码中导入 asyncio
时,它会尝试从 zeromq
导入,但失败了。
我做了一个丑陋的 hack 来解决这个问题。我 post 它可能对某人有帮助
former_path = sys.path[:]
sys.path = [v for v in sys.path if 'zmq' not in v]
import asyncio
sys.path = former_path
到目前为止,我找不到任何副作用