Module missing error - python-3.x

I have created the exe by using py2exe and this works fine in windows 8 , Application window runs without python installing. But same distribution or exe gives an error in windows 7 and windows XP. Below is the traceback for the same.
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\PySide\_utils.py", line 93, in get_pyside_dir
File "<loader>", line 10, in <module>
File "<loader>", line 8, in __load
ImportError: (DLL load failed: The specified module could not be found.) 'C:\\Users\\Test\\Desktop\\123\\dist\\PySide.QtCore.pyd'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "TopicMapParser.py", line 11, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\PySide\__init__.py", line 41, in <module>
File "C:\Python34\lib\site-packages\PySide\__init__.py", line 11, in _setupQtDirectories
File "C:\Python34\lib\site-packages\PySide\_utils.py", line 95, in get_pyside_dir
File "C:\Python34\lib\site-packages\PySide\_utils.py", line 88, in _get_win32_case_sensitive_name
File "C:\Python34\lib\site-packages\PySide\_utils.py", line 63, in _get_win32_short_name
FileNotFoundError: [WinError 3] The system cannot find the path specified.
Please help on this issue.

We are shooting into the dark when you don't post your code. So please, next time, please post your code.
Look at the errors. Python has excellent error handling and naming conventions to make it really clear on whats going wrong. It can't find the module that you are requesting. Have you attempted to update your python? To attempt to find the module that you are attempting to import? Have you double checked to make sure you did not misspell the module name? Have you searched around on stackoverflow for existing similar questions?
You are getting an ImportError and FileNotFoundError meaning it is not installed, file path is broken or you misspelled the module name.
It seems like you are trying to install QtCore, which is a package that you need to manually install using sudo apt-get install python-qt4. For windows, you have to install something that allows you to do apt-get since it is a Unix/Linux command. Try using wuinstall.

I have tried to generate the exe by using Py2exe in Python 3.4. It creates the exe and it works fine in the same machine. But it was giving an error in other machine. I have also tried with cx-freeze , still I was not able to resolve the issue. But I installed the Pyside in Python 2.7 and used py2exe for the same version and it worked nicely.
Below is the code that I have used in setup.py.
from distutils.core import setup
import py2exe
data = [('', [r'hpXMLTools.ico']), ('imageformats',[r'C:\Python34\Lib\site-packages\PySide\plugins\imageformats\qico4.dll'])]
setup(windows=[{'script': 'TopicMapParser.py',
'icon_resources': [(1, 'hpXMLTools.ico')]
}],
data_files=data,
options={
'py2exe':
{
'optimize': 2
}
}, requires=['PySide', 'xlsxwriter'])

Related

Python 3.11 - creating a virtual Env - Frozen runpy

After following a thread on how to fix the pip SLL issue, now this:
So far I have spent more time fixing environments than actual training.
I am using an Oracle appliance with Linux server 7 on it.
Has anyone seen this error and know a fix for it, please?
[oracle#localhost myProjects]$ python3 -V
Python 3.11.0a4
[oracle#localhost myProjects]$ python3 -m venv env
Traceback (most recent call last):
File "<frozen runpy>", line 189, in _run_module_as_main
File "<frozen runpy>", line 148, in _get_module_details
File "<frozen runpy>", line 112, in _get_module_details
File "/usr/local/lib/python3.11/venv/__init__.py", line 7, in <module>
import logging
^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/logging/__init__.py", line 26, in <module>
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/re/__init__.py", line 125, in <module>
from . import _compiler, _parser
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/re/_compiler.py", line 18, in <module>
assert _sre.MAGIC == MAGIC, "SRE module mismatch"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: SRE module mismatch
There are a couple of possible solutions on a Chinese blog platform I haven't met before. One by weixin_42424046 and one by jacke121.
Set module load apps/python/3.6.3/gnu in .bashrc, and source .bashrc after saving, but still report the same error when running python. the solution is
vi .bash_profile
Add at the end of the file
export PYTHON_HOME=/g1/app/apps/python/3.6.3/gnu/
export PATH=$PYTHON_HOME/bin:$PATH
After saving, source .bash_profile
Re-run python problem solved.
This problem is caused by the environment is 32-bit python
Change the environment to a 64 python environment
These links don't answer the exact question but can give you some ideas for further research.

Q: How to fix the missing dependancies in pyzbar

I am currently using spyder via anaconda with python 3.8.5 on windows 10 and I am trying to use the pyzbar package to make a barcode reader. When I try to run the script I get this error message when trying to run from pyzbar.pyzbar import decode and from pyzbar import pyzbar:
Traceback (most recent call last):
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 58, in load
dependencies, libzbar = load_objects(Path(''))
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 50, in load_objects
deps = [
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 51, in <listcomp>
cdll.LoadLibrary(str(directory.joinpath(dep)))
File "C:\Users\norinhan\Anaconda3\lib\ctypes\__init__.py", line 459, in LoadLibrary
return self._dlltype(name)
File "C:\Users\norinhan\Anaconda3\lib\ctypes\__init__.py", line 381, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'libiconv.dll' (or one of its dependencies). Try using the full path with constructor syntax.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<ipython-input-1-95ae0761f4b5>", line 1, in <module>
from pyzbar.pyzbar import decode
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\pyzbar.py", line 7, in <module>
from .wrapper import (
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\wrapper.py", line 139, in <module>
zbar_version = zbar_function(
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\wrapper.py", line 136, in zbar_function
return prototype((fname, load_libzbar()))
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\wrapper.py", line 115, in load_libzbar
libzbar, dependencies = zbar_library.load()
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 60, in load
dependencies, libzbar = load_objects(Path(__file__).parent)
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 50, in load_objects
deps = [
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 51, in <listcomp>
cdll.LoadLibrary(str(directory.joinpath(dep)))
File "C:\Users\norinhan\Anaconda3\lib\ctypes\__init__.py", line 459, in LoadLibrary
return self._dlltype(name)
File "C:\Users\norinhan\Anaconda3\lib\ctypes\__init__.py", line 381, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\libiconv.dll' (or one of its dependencies). Try using the full path with constructor syntax.
When trying to run just import pyzbar it will compile, but it will not be able to access any of the function. When I try I get this message:
Traceback (most recent call last):
File "<ipython-input-3-26272af93b8a>", line 1, in <module>
pyzbar.pyzbar.decode()
AttributeError: module 'pyzbar' has no attribute 'pyzbar'
I have looked up the documentation for pyzbar on github which states "The zbar DLLs are included with the Windows Python wheels", but have not found this anywhere. The closest to "Windows Python wheels" I have found is the wheel package which does not contain any information about pyzbar.
Any advice on how to fix this?
Visit https://pypi.org/project/pyzbar/#files to download pyzbar-0.1.8-py2.py3-none-win_amd64.whl.
You can find all the DLL files inside the wheel package.
I have just encountered this problem.
If your OS & python are x64 version, it's just because of lack of vc 2013 x64 runtime.
You can find Visual C++ Redistributable Packages for Visual Studio 2013 here
download & install.
I was facing similar issue just installed Visual
C++ 64 bit version on my computer and restarted. Choose between vcredist_x86.exe or vcredist_x64.exe based on your machine.
https://www.microsoft.com/en-us/download/confirmation.aspx?id=40784. Hope this solves your issue as well.

Pyttsx3 not working with PyInstaller

I get this error from the exe generated by PyInstaller when using Pyttsx3. The code works fine in python. I've tried using other versions of PyInstaller and Pyttsx but it doesn't make a difference. I've also tried Py2exe which is also not working with Pyttsx3, does anyone know what's causing this?
The code
import pyttsx3
engine = pyttsx3.init()
engine.say('Test')
engine.runAndWait()
The error after running the exe generated
Traceback (most recent call last):
File "site-packages\pyttsx3\__init__.py", line 44, in init
File "c:\python34\lib\weakref.py", line 125, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Test.py", line 85, in <module>
File "site-packages\pyttsx3\__init__.py", line 46, in init
File "site-packages\pyttsx3\engine.py", line 52, in __init__
File "site-packages\pyttsx3\driver.py", line 75, in __init__
File "importlib\__init__.py", line 109, in import_module
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'pyttsx3.drivers'
Try this:
import pyttsx3
from pyttsx3.drivers import sapi5
engine = pyttsx3.init()
engine.say('Test')
engine.runAndWait()
Explanation:
You actually need to import an extra module from pyttsx3.
Goto location:
C:\Users\username\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\PyInstaller\hooks
Create a newfile "hook-pyttsx3.py"
inside file, copy the code below..
#-----------------------------------------------------------------------------
# Copyright (c) 2013-2020, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
#-----------------------------------------------------------------------------
""" pyttsx3 imports drivers module based on specific platform. Fount at https://github.com/nateshmbhat/pyttsx3/issues/6 """
hiddenimports = [
'pyttsx3.drivers',
'pyttsx3.drivers.dummy',
'pyttsx3.drivers.espeak',
'pyttsx3.drivers.nsss',
'pyttsx3.drivers.sapi5', ]
Now your program will run without getting error.
Click here Github issue created
Try this:
pyinstaller --hidden-import=pyttsx3.drivers --hidden-import=pyttsx3.drivers.dummy --hidden-import=pyttsx3.drivers.espeak --hidden-import=pyttsx3.drivers.nsss --hidden-import=pyttsx3.drivers.sapi5
Hidden import argument for pyinstaller import 3 rd party packages into build. By adding above lines to pyinstaller will create a spec file with hidden-import =[‘pyttsx3.drivers’,’pyttsx3.drivers.dummy’,....] which will rectify the error “no module named pyttsx.driver’ but eventually u will end up other error also which i am unable to solve.
I've just fixed pyttsx3 compatibility in #101. In a couple of weeks you will be able to:
pip install "pyinstaller-hooks-contrib>=2021.2"
but until then you can use the Github version:
pip install -U https://github.com/pyinstaller/pyinstaller-hooks-contrib/archive/refs/heads/master.zip
Add the --clean option the first time you run PyInstaller after using pip (unless you're using auto-py-to-exe which blocks PyInstaller's caching). It should then work on all platforms without using any --hiddenimport-ing.

How to assort files of an executable python3 program made with cx_freeze?

I developed a project in python 3.4.1 and pyqt4. Then I converted my python program to executable file using cx_freeze module.
Everything is perfectly fine, but I found two problems here:
Size of program gets really high.
I like to assort my files in special folders by their format type, for example all of the .dll files in a folder called DLL and something like that, but when I do this I ran into some problems.
Is it really possible ? If yes give me some information and if no, what can I do to solve my problems. Thanks
Error I get :
cx_Freeze: Python error in main script
Traceback (most recent call last): File
"C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line
27, in
exec(code, m.dict) File "MY APP.py", line 1, in File "c:\Python\64-bit\3.4\lib\importlib_bootstrap.py", line 2237, in
_find_and_load File "c:\Python\64-bit\3.4\lib\importlib_bootstrap.py", line 2226, in
_find_and_load_unlocked File "c:\Python\64-bit\3.4\lib\importlib_bootstrap.py", line 1191, in
_load_unlocked File "c:\Python\64-bit\3.4\lib\importlib_bootstrap.py", line 1161, in
_load_backward_compatible File "ExtensionLoader_PyQt4_QtCore.py", line 22, in File "ExtensionLoader_PyQt4_QtCore.py", line
21, in bootstrap ImportError: No module named PyQt4.QtCore

cx_freeze doesn't work in my script

I freeze a script using cx_freeze (4.3.1) in python 3.4.
The script works perfectly running in IDLE. It uses tkinter, re, and reportlab to create a pdf form.
Then the following error occurrs when I run the exe.
PS C:\Python34\build\exe.win32-3.4> .\CREEPING_cx_freeze.exe
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__)
File "CREEPING_cx_freeze.py", line 6, in <module>
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2214, in _find_and_load
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2203, in _find_and_load_unlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked
File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible
AttributeError: 'module' object has no attribute '_fix_up_module'
It looks like everything is working. Everything is created in the build folder, but the compiled executable does not work.
I tried searching for a solution but did not find any. Could somebody help me with this?
I´m using win 8 64 bits
Wrong version installed.
pip installs 64 bits but it doesn,t work.
running the 32bits version...works

Resources