PyInstaller ImportError: cannot import name 'SelectorEventLoop' - python

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

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

Related

How to solve ModuleNotFoundError: No module named 'openpyxl.cell._writer'?

I am trying to build an exe file for the GUI that I created using python POyqt5. After completing the process, I try to launch the UI and I get the following error:
Traceback (most recent call last):
File "main_3.py", line 14, in <module>
import openpyxl
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "openpyxl\___init__.py", line 6, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "openpyxl\workbook\____init__.py", line 4, in <module>
File "PyInstaller\loader\pyimode2_importers.py", line 499, in exec_module
File "openpyxl\workbook\workbook.py", line 9, in <module>
File "PyInstaller\loader\pyimode2_importers.py", line 499, in exec_module
File "openpyxl\worksheet\_write_only.py", line 13, in <module>
File "openpyxl\worksheet\_writer.py", line 23, in init openpyxl.worksheet._writer
ModuleNotFoundError: No module named 'openpyxl.cell._writer'
[13336] Failed to execute script 'main_3' due to unhandled exception!
I have openpyxl installed and I have also got it imported in my python script. Still, this error remains. Any leads on solving this will be appreciated.
Thanks!
Assuming you are creating the .exe with pyinstaller, try:
pyinstaller YOUR_FILE.py --hidden-import openpyxl.cell._writer
It lets pyinstaller know that openpyxl.cell._writer must be imported. It seems like this module import is done in a "hidden" way in your Python script. Therefore, it is not visible for pyinstaller and must be mentioned explicitly.
downgrade openpyxl to version 3.0.9 will also help. it works for me.
pip unistall openpyxl
pip install openpyxl=3.0.9

Python based exe throwing error at CMD (pynput module)

So this is the error it's throwing in cmd windows 10. Seems to be something to do with pynput? Not really sure what I can do to fix this and appreciate any help.
C:\Users\Michael\Desktop\herprogram\dist\beeb>beeb.exe
Traceback (most recent call last):
File "C:\Users\Michael\Desktop\herprogram\beeb.py", line 5, in <module>
import pynput
File "c:\python38\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "pynput\__init__.py", line 40, in <module>
File "c:\python38\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[11880] Failed to execute script beeb
Many thanks
I switched to a different module pywinauto which is officially supported by pyinstaller and used:
import pywinauto
pywinauto.mouse.double_click(button='left', coords=(0, 0))
This solved the issue. Thanks guys

Error when opening the exe file which is made from darkflow

I am using darkflow for custom object detection it is working perfectly fine and it is running perfectly through anaconda prompt. I made the exe using pyinstaller, So when I was running the exe it is showing the above error. Can anyone help me to get rid of this? I tried installing darkflow globally also but it didn't work.
Traceback (most recent call last):
File "demo.py", line 1, in <module>
from darkflow.net.build import TFNet
File "c:\users\camfyvision\anaconda3\envs\darkflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "darkflow\net\build.py", line 7, in <module>
from .framework import create_framework
File "c:\users\camfyvision\anaconda3\envs\darkflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "darkflow\net\framework.py", line 1, in <module>
from . import yolo
File "c:\users\camfyvision\anaconda3\envs\darkflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "darkflow\net\yolo\__init__.py", line 2, in <module>
from . import predict
File "c:\users\camfyvision\anaconda3\envs\darkflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "darkflow\net\yolo\predict.py", line 7, in <module>
from ...cython_utils.cy_yolo_findboxes import yolo_box_constructor
File "c:\users\camfyvision\anaconda3\envs\darkflow\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
File "darkflow\cython_utils\cy_yolo_findboxes.pyx", line 1, in init darkflow.cython_utils.cy_yolo_findboxes
import numpy as np
ModuleNotFoundError: No module named 'darkflow.cython_utils.nms'
This is the error I got when I did drag and drop of the exe into propmt and also I am providing below the corresponding information I got regarding the error when I was making the exe using pyinstaller.
136360 INFO: Updating manifest in C:\Users\CamfyVision\AppData\Roaming\pyinstaller\bincache00_py36_64bit\darkflow.cython_utils.cy_yolo_findboxes.pyd
136361 INFO: Updating resource type 24 name 2 language 1033
136413 INFO: Updating manifest in C:\Users\CamfyVision\AppData\Roaming\pyinstaller\bincache00_py36_64bit\darkflow.cython_utils.cy_yolo2_findboxes.pyd
136414 INFO: Updating resource type 24 name 2 language 1033

Pyinstaller throws "Import Error:requests> 2.18.0 is required by the google.resumable media.requests subpackage."

I used pyinstaller to convert my .py file to .exe, but as i try to execute the exe it throws the following error:
Import Error:requests> 2.18.0 is required by the google.resumable media.requests subpackage.
My pip version is : pip 19.1.1
here's the code i used :
pyinstaller -F AdminPanel.py
i tried installing it using pip, but it says that its already installed.
Thanks in advance
Complete Error is:
Resources.Distribution Plot Found: The requests-2.18.0 distribution was not found and is required by the
The above exception as the direct cause of the following exception:
Network
Traceback (most recent call last):
File AdninPanelUI.py, line 11, in module>
File "d: Nother stuffiapplications\python\installation\lib\site-packages\PyInstaller\loader\pyimod83_importer
627, in exec_module
exec(bytecode, module. dict)
File "site-packages\google cloud storage__init__.py", line 39, In <module>
File "d: other stufflapplications\python\installation\llb\site-packages\PyInstaller\loader\pyimode3_importer
627, in exec_module
exec(bytecode, module. dict)
File site-packages\google cloud storage\blob.py", line 44, in <module
File "d: other stuff applications\python\installation\lib site-packages\PyInstaller loader\pyimode3_importer
627, in exec_module
exec(bytecode, module. dict)
File "site-packages\google\resumable_media\requests_init_.py", 1ine 673, in <module>
File string", 1ine 3, in raise from
ImportError:requests
2.18.e is required by the google.resumable_media.requests
subpackage.
It can be installed via
pip Install google-resumable-media[requests).
17008) Failed to execute script Admin Panel
This is how i fixed the error :
Made a hook(python file) named it
hook-google.resumable_media.requests
and the content of it is as follow :
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('requests')
Then after just past this file to the hooks folder inside pyinstaller where all the other hooks are.
Hope it fixed the error for you.

Tensorflow-gpu with pyinstaller

Trying to distribute a program that relies on tensorflow...
Using tensorflow it works nicely both as script and with pyinstaller.
Using tensorflow-gpu it works as script but not with pyinstaller.
The cuda and cudnn dlls have been copied into the bundle folder by pyinstaller.
I use python 3.6.5 and tensorflow 1.7.0. (Can change version if it helps...)
Error message:
Traceback (most recent call last):
File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.dict)
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper
File "importlib__init__.py", line 126, in import_module
ModuleNotFoundError: No module named 'tensorflow.python._pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "interface.py", line 14, in
File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.dict)
File "site-packages\tensorflow__init__.py", line 24, in
File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.dict)
File "site-packages\tensorflow\python__init__.py", line 49, in
File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.dict)
File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
ImportError: Traceback (most recent call last):
File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.dict)
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper
File "importlib__init__.py", line 126, in import_module
ModuleNotFoundError: No module named 'tensorflow.python._pywrap_tensorflow_internal'
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
[10816] Failed to execute script interface
Make sure you are also packaging MSVCP140.DLL, as missing this from the %PATH% can throw this error.
I tend to use cx_Freeze instead of pyinstaller when distributing tensorflow applications. Once you overcome the error cx_Freeze has with scipy, it's simpler overall.
Maybe this can help. I manually rename the file _pywrap_tensorflow_internal.pyd to tensorflow.python._pywrap_tensorflow_internal.pyd in the dist folder. Everything works.
I fixed this problem by making dirs as ".../dist/[MmyPyName]/tensorflow/python/_pywrap_tensorflow_internal.pyd"
tensorflow-gpu = 1.10.0
python = 3.6.2
cuda = 9.0
cudnn = 7.3.0
When installing it with pyinstaller, make sure that in the .spec file include this as hidden import:
hiddenimports=['tensorflow.python._pywrap_tensorflow_internal',],
This will include the missing module in the correct path.

Categories