Queue Import error after running exe - python

i created exe using py2exe after that i facing this below error
i checked in lib directory and Queue.py is already present in that directory
please help me to resolve this issue
im using python 2.7
Traceback (most recent call last):
File "Game2048.py", line 12, in <module>
File "pynput\__init__.pyc", line 23, in <module>
File "pynput\keyboard\__init__.pyc", line 44, in <module>
File "pynput\keyboard\_win32.pyc", line 32, in <module>
File "pynput\_util\__init__.pyc", line 34, in <module>
File "six.pyc", line 203, in load_module
File "six.pyc", line 115, in _resolve
File "six.pyc", line 82, in _import_module
ImportError: No module named Queue

py2exe decides which modules to include in the final ZIP-file or executable by examining the import statements in those module(s) explicitly mentioned in setup.py. It then adds these imported modules to the dependencies of the executable and checks all import statements in these newly added modules to find further necessary modules and so on until no more new modules can be found in the imports.
Here, the module Queue is imported in a dynamical way, basically by calling something like __import__("Queue") which can't be automatically recognized by py2exe. Therefore the module isn't seen as necessary.
To solve this add an artificial dependency in a module which is already added to the executable:
if False:
import Queue
The code has no effect but py2exe sees the import statement and will follow it.

Related

Pyinstaller doesn't recognize docx2pdf library

my issue is that i've been trying to make an exe file with a .py that I created, but it doesn't work. I executed the converted .exe file from the console to see the log and I got this:
Traceback (most recent call last):
File "professors.py", line 10, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "docx2pdf\__init__.py", line 13, in <module>
File "importlib\metadata.py", line 551, in version
File "importlib\metadata.py", line 524, in distribution
File "importlib\metadata.py", line 187, in from_name
importlib.metadata.PackageNotFoundError: docx2pdf
[6940] Failed to execute script professors
I've been reading about the issue and it seems that pyinstaller doesn't recognize the docx2pdf import. I read in a website that I have to add it in a folder called site-packages, but it is supposed to have another folder inside called pyInstaller, which is not there. I also tried adding the folder manually but it still didn't work. I also tried with the --hidden-imports method but im not sure how to exactly use it.
I will have to apply this to other imports that I have also.
Any ideas? Thanks in advance!
I had a identical issue. I removed lines 7-13 from the docx2pdf module:
try:
# 3.8+
from importlib.metadata import version
except ImportError:
from importlib_metadata import version
__version__ = version(__package__)
and line 119...
print(__version__)
After that, it worked. Modifying the module probably isn't the best solution, and of course I'd recommend backing up the module before modifying it, but I hope it works for you too.

Python shell working differently on different location in the same machine inside same virtual environment

I have a cloud instance of a Linux machine (openSuSE) with multiple users.
I have created a virtual environment and installed all my required libraries (including Klein).
I have two users "a" and "b".
While logged in as "a" and inside virtualenv, when I open python shell at home directory and type
import klein
it imports normally.
Now when I change directory to
/home/b/
and run the same (open python shell, import klein) while being in the same virtualenv, it gives me an error.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/a/.local/lib/python3.6/site-packages/klein/__init__.py", line 3, in <module>
from klein._plating import Plating
File "/home/a/.local/lib/python3.6/site-packages/klein/_plating.py", line 16, in <module>
from .app import _call
File "/home/a/.local/lib/python3.6/site-packages/klein/app.py", line 19, in <module>
from twisted.internet import endpoints, reactor
File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/endpoints.py", line 58, in <module>
from twisted.protocols.tls import TLSMemoryBIOFactory
File "/home/a/.local/lib/python3.6/site-packages/twisted/protocols/tls.py", line 63, in <module>
from twisted.internet._sslverify import _setAcceptableProtocols
File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/_sslverify.py", line 158, in <module>
verifyHostname, VerificationError = _selectVerifyImplementation()
File "/home/a/.local/lib/python3.6/site-packages/twisted/internet/_sslverify.py", line 141, in _selectVerifyImplementation
from service_identity import VerificationError
File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/__init__.py", line 7, in <module>
from . import cryptography, pyopenssl
File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/cryptography.py", line 16, in <module>
from .exceptions import SubjectAltNameWarning
File "/home/a/.conda/envs/mm/lib/python3.6/site-packages/service_identity/exceptions.py", line 21, in <module>
#attr.s
AttributeError: module 'attr' has no attribute 's'
Command "which python" gives same address at both location which is my virtualenv python address and that should be expected.
But what causes this weird python shell behavior.
Thank you
I solved it and a very shameful reason caused the error.
One of the modules Twisted uses is "attr" module. I had named one of my files attr.py and that is what was causing all the error.
I myself am not deleting this question if moderation has no problem, maybe somebody like me might be stuck at the same situation. It may help them.
Never name your python files same as that of any standard module unless overriding.
Also if your issue persists, then Jean's answer will definitely resolve it.
There can be multiple different Python packages that provide the same Python module. For example, there are at least two packages that provide the attr module:
https://pypi.org/project/attr/
https://pypi.org/project/attrs/
It's possible you've installed the wrong package based on the requirements. You can check what you have installed with pip freeze.

Converting .py to .exe getting error no module named userlist

I had created a .py file using below
from appd.request import AppDynamicsClient
import requests
import datetime as db
import time
import matplotlib.pyplot as plt
import pylab
import json
i had used py2exe for converting it into .exe , i had created a setup.py file in which included all the required packages command used
python setup.py py2exe --include package name
it is running fine and creating two folder named dist and build, In dist exe file is present when running the file it is giving the following error
Traceback (most recent call last):
File "appd\__init__.pyc", line 10, in <module>
File "appd\model\__init__.pyc", line 8, in <module>
File "six.pyc", line 92, in __get__
File "six.pyc", line 160, in _resolve
File "six.pyc", line 82, in _import_module
ImportError: No module named UserList
I am not using any module as userlist
I had imported UserList in the file and it was working fine
Actually, problem is that User list package is inside the six package so it is dynamically loaded on the time generation of .exe so it was not able to load the package that's why it was throwing the error.

ImportError: No module named geometry while running executables obtained from pyinstaller

Traceback (most recent call last):
File "<string>", line 1, in <module>
File py_installer/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 270, in load_module
File py_installer/PyInstaller-2.1/FaceMatcher/build/FaceMatcher/out00-PYZ.pyz/proj_code", line 11, in <module>
File PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 270, in load_module
File PyInstaller-2.1/FaceMatcher/build/FaceMatcher/out00-PYZ.pyz/skimage.transform", line 1, in <module>
File py_installer/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 270, in load_module
File py_installer/PyInstaller-2.1/FaceMatcher/build/FaceMatcher/out00-PYZ.pyz/skimage.transform.hough_transform", line 7, in <module>
File py_installer/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 409, in load_module
File "_hough_transform.pyx", line 13, in init skimage.transform._hough_transform (skimage/transform/_hough_transform.c:7337)
File "py_installer/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 270, in load_module
File "py_installer/PyInstaller-2.1/FaceMatcher/build/FaceMatcher/out00-PYZ.pyz/skimage.draw", line 1, in <module>
File "py_installer/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 409, in load_module
File "_draw.pyx", line 1, in init skimage.draw._draw (skimage/draw/_draw.c:7257)
ImportError: No module named geometry
I have been getting above error. Could some one please tell me how would i fix it?
The problem is skimage.transform requires on a small 'chain' of hidden imports. These are imports that happen in a variety of ways Pyinstaller cannot detect automatically, namely using __import__, etc. So, you must tell Pyinstaller directly about these imports so it knows to inspect them and add them to your build.
You can do this in two ways:
The --hidden-import command-line flag, which is useful if you have only a few modules to specify.
'hook' files, which can help you group a few hidden imports based on what module requires them.
For example, for your specific situation you can create a file called hook-skimage.transform.py and put the following in it:
hiddenimports = ['skimage.draw.draw',
'skimage.draw._draw',
'skimage.draw.draw3d',
'skimage._shared.geometry',
'skimage._shared.interpolation',
'skimage.filter.rank.core_cy']
You may not need all of those modules specified. Your build was only lacking skimage._shared.geometry so you could try only including that file with the --hidden-import command-line flag, or only including skimage._shared.geometry in your hook-skimage.transform.py file. However, those specific hidden imports fixed my scenario on Windows 7 64-bit with skimage 0.9.3.
Then, tell pyinstaller where to look for your extra hook files. So, if you put the hook-skimage.transform.py file in your '.' directory you need to modify your pyinstaller build command to include --additional-hooks-dir=.
This will cause pyinstaller to inspect the modules you specified when it tries to import skimage.transform.hough_line as your output mentioned.

Using kinterbasdb with py2exe

I'm trying to create executable program with py2exe. I get the following error message when kinterbasdb is imported:
Traceback (most recent call last):
File "AlarmReporter.py", line 13, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "kinterbasdb\__init__.pyo", line 119, in <module>
File "zipextimporter.pyo", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading kinterbasdb\_kinterbasdb.pyd
Here's my very basic setup.py for py2exe:
from distutils.core import setup
import py2exe
import sys
setup(
options={'py2exe': dict(bundle_files=1, optimize=2)},
console=['AlarmReporter.py'],
zipfile=None,
)
I'm having problem understanding the error message and have no idea how to fix it.
Try to exclude libfbclient dll
Error while transforming .py to .exe
If that doesn't work , try to use the new fdb driver (the future replacement of kinterbasdb)
http://permalink.gmane.org/gmane.comp.db.firebird.python/104
(it doesn't need compiling only the libfbclient.dll)
Another option is to use the pure driver that doesn't need no dll and no c generated binary
https://github.com/nakagami/pyfirebirdsql
But you will use it at your own risk ;)

Categories