Sylvain Biehler
Sylvain Biehler

Reputation: 1433

PyInstaller ImportError: cannot import name 'SelectorEventLoop'

Using PyInstaller to generate an .exe on a windows platform, i have an error when runnig the .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

I am using python 3.6.4 and pyinstaller 3.3 I just added ayncio 3.4.3 to the project (everything worked find before that)

Any idea would be welcomed

Upvotes: 2

Views: 1794

Answers (1)

Sylvain Biehler
Sylvain Biehler

Reputation: 1433

After digging a lot, i came up with a solution.

The sources of the issue are:

  • the zmq (for zeromq) i use. It embeds its own asyncio
  • PyInstaller modifies sys.path to add the libraries from zeromq.

When importing asyncio in my code, it tries to import the one from zeromqand fails.

I made an ugly hack to get around that. I post it so it might help someone

former_path = sys.path[:]
sys.path = [v for v in sys.path if 'zmq' not in v]
import asyncio
sys.path = former_path

So far, i couldn't find any side effect

Upvotes: 1

Related Questions