Error when run exe "ModuleNotFoundError: No module named 'babel.numbers" [duplicate] - exe

I'm trying to install python application on Windows with pyinstaller where I'm using tkcalendar. Application is working but the tkcalendar.Calendar isn't.
When I'm running application without installation everything works but if I do this, Calendar widget does not appear.
I think that pyinstaller sees this module but he has problems with modules that tkcalendar is using.
I tried to run pyinstaller with --path=/.../python/Lib/site-packages but this didnt worked. Also copying module files to application directory didn't help.

The issue does not come from tkcalendar but from the fact that PyInstaller does not detect second level imports. A way to solve this issue is explained in tkcalendar's documentation in the HowTos section:
When bundling an application with PyInstaller, there is an
issue with the
detection of the babel dependency of tkcalendar. This can be fixed by
using the --hidden-import option:
$ pyinstaller --hidden-import babel.numbers myscript.py
or by editing the .spec file:
hiddenimports=["babel.numbers"]

Add following code to your python script, while bundling with pyinstaller
import babel.numbers

If anyone found the same problem.
In tkcalendar 1.5.0 there is problem with import in calendar.py.
Locate the tkcalendar folder (probably /.../python/Lib/site-packages/tkcalendar) and under calendar.py add an additional import for the missing module:
import calendar
from babel.dates import format_date, parse_date, get_day_names, get_month_names
from babel.numbers import * # Additional Import```

Related

ModuleNotFoundError: No module named 'sklearn.utils._typedefs'

When I try to execute the exe file made my pyinstaller I got the error message
No module named 'sklearn.utils._typedefs'. I use from sklearn.ensemble import RandomForestClassifier in my python code.
I did use the --hidden-import and solve the problem before but when I try use the different version's python it didn't works
The command I use is
pyinstaller --hidden-import="sklearn.utils._cython_blas" --hidden-import="sklearn.neighbors.typedefs" --hidden-import="sklearn.neighbors.quad_tree" --hidden-import="sklearn.tree._utils" -F myprgname.py
The old setting works
Python 3.6.8
pyinstaller==4.6
pyinstaller-hooks-contrib==2021.3
python-dateutil==2.8.2
pytz==2021.3
scikit-learn==0.24.2
The new setting (got error message above)
Python 3.7.8
pyinstaller==5.0.1
pyinstaller-hooks-contrib==2022.4
python-dateutil==2.8.2
pytz==2022.1
scikit-learn==1.0.2
any suggestion is appreciated.
Had the same issue today, I resolved it by adding news hidden imports :
--hidden-import="sklearn.utils._typedefs"
This one may be sufficient for your issue, but for me, I had to add also :
--hidden-import="sklearn.neighbors._partition_nodes"
Here is the full command that I used :
pyinstaller --hidden-import="sklearn.utils._cython_blas" --hidden-import="sklearn.neighbors.typedefs" --hidden-import="sklearn.neighbors.quad_tree" --hidden-import="sklearn.tree._utils" --hidden-import="sklearn.neighbors._typedefs" --hidden-import="sklearn.utils._typedefs" --hidden-import="sklearn.neighbors._partition_nodes" --onefile MyPythonScript.pyw
My environment :
Python 3.9.12
Pyinstaller 5.0.1
pyinstaller-hooks-contrib==2022.4
python-dateutil==2.8.2
scikit-learn==1.0.2
pytz == none
I had the same issue and I could't solve it adding the --hidden-import flag.
I had scikit-learn==1.0.2 and pyinstaller==4.10
Downgrading it to scikit-learn==1.0.1 solved the problem.
pip install -U scikit-learn==1.0.1
I guess it is a compatibility problem.
ModuleNotFoundError: No module named 'sklearn.utils'.
This is the problem you have when converting from python to an executable.
Knowing that I am using python 3.8, I had the same issue today. I resolved it by adding new hidden imports:
--hidden-import="sklearn.utils._typedef"
Didn't accept it at the command prompt CMD

Pyinstaller does not properly include numpy in Mac bundle

If I include numpy in my script the bundle application does not even open. However, if I run the application from the console everything is fine. So:
pyinstaller -w myScript.spec
with import numpy as np in one of the modules does not create a proper executable. However:
python3.7 myScript.py
runs without problems. Even more, if I comment the import numpy as np line the executable is created without problem. I have also used numpy in another console-only script without problems.
So, how can I make PyInstaller include numpy in the bundle app?
I checked the warn-myScript.txt file from PyInstaller and there are lots of modules from numpy.core that are not found, for example: numpy.core.sqrt.
But I have no idea where to find these modules.
I tried doing what j4n7 suggested here, but it did not work.
I am using Python3.7, numpy 1.15.4 and PyInstaller 3.4
I installed Python from the Python web page and numpy and Pyinstaller using pip.
In a different computer I installed Python3.7 from homebrew and I have the same problem
I installed miniconda and then created an environment with numpy 1.15.4, Pyinstaller 3.4 and python3.7.1. Within the environment, I can create the bundle app with no problem.
However, the bundle app goes to 600MB. I will start a new question regarding how to reduce the size of the bundle app.

Python 3.6 cx_freeze ModuleNotFoundError: No module named Tkinter

I froze a python 3.6 program with cx_freeze, and it worked just fine. But as soon as I tried to run it, I got this error message.
Does anyone know what to do? Please help!
try using
import tkinter
(small 't' instead of capital)
Try checking the dir names in the 'lib' folder (in my case it was 'build\exe.win-amd64-3.6\lib'). I had a similar issue (without the 'ImportError: DLL load failed...') and found that the 'lib' directory contained a "Tkinter" folder. Changing its name to lowercase 'tkinter' did the trick and made the .exe run just fine.
If you read the error more clearly, it stated in a comment that if importing _tkinter failed, your computer isn't configured to use tkinter. You should download tk and ttk to make it work.
And According to http://wiki.python.org/moin/TkInter :
If it fails with "No module named _tkinter" or "Tkinter", your Python configuration
needs to be modified to include this module (which is an extension
module implemented in C). Do not edit Modules/Setup (it is out of
date). You may have to install Tcl and Tk (when using RPM, install the
-devel RPMs as well) and/or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in
the default locations, simply rerunning "make" should build the
_tkinter extension.

Pyinstaller Cannot find xlrd

I am running Python 3.5.1 and PyInstaller 3.2 on Windows.
I need to compile my script into an exe. I have done this with pyintaller before with different scripts and have had no issues. Pyinstaller is having trouble importing xlrd. I have tried:
--hidden-import=xlrd
and also
--hidden-import xlrd and neither has worked.
I have heard about hooks but I cannot find any documentation on how to set up the hook-xlrd.py file.
I have been getting the error:
ImportError: No Module called xlwt
The script runs perfectly from the Command Prompt.
Somehow, your application requires xlwt. So do a pip install xlwt and then add --hidden-import=xlwt to your arguments. For a more comprehensive guide, see here.

Xlwings - Issue with running on 64-bit python? [duplicate]

I am using python 3.4 on windows 7. In order to open a doc file I am using this code:
import sys
import win32com.client as win32
word = win32.Dispatch("Word.Application")
word.Visible = 0
word.Documents.Open("MyDocument")
doc = word.ActiveDocument
I'M not sure why is this error popping up every time:
ImportError: no module named win32api
Although I have installed pywin32 from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32
and I have also checked the path from where I am importing. I have tried reinstalling pywin32 as well but that doesn't remove the error.
Try to install pywin32 from here :
http://sourceforge.net/projects/pywin32/files/pywin32/
depends on you operation system and the python version that you are using. Normally 32bit version should works on both 32 and 64 bit OS.
EDIT: moved to https://github.com/mhammond/pywin32/releases
This is a bug in the library itself, probably they used a different python implementation for creating this.
What they are trying to import is the site-packages\win32\win32api.pyd file, but the win32 folder is not in the path that python searches in, but site-packages is.
Try to replace the import win32api (inside win32com\__init__.py) to from win32 import win32api
I encountered the same error yestoday with Python 3.6.1 on Windows 7, and resolved it by "pip install pypiwin32".
Had the same error trying to import win32com.client (using Python 2.7, 64-bit). I agree with TulkinRB, there seem to be path issues, but the fix suggested did not work for me, since I also could not import win32.
Perhaps my fix will also work in Python 3.4.
Eventually, installing the .exe from SourceForge as an administrator (as suggested in Rina Rivera's answer here) allowed me to import win32com.client from IDLE, but not when I executed the script I was originally trying to run.
In the end, I discovered 3 differences in the sys.path that had been extended when I installed as admin and opened IDLE, but were not applied when executing a script. By extending the sys.path in my script, I was able to get rid of the import errors when I executed it:
import sys
sys.path.extend(('C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin'))
Finally, if you want more than a temporary fix, the sys.path could be permanently extended by establishing IDLESTARTUP or PYTHONSTARTUP variables (as described here and here).
You can create the __init.py file inside the win32 folder and then go inside the win32com folder and change its __init__.py file, where it is import win32api, change to from win32 import win32api
I ended up debugging and copying and pasting the necessary files into the appropriate folders. It's a work-around until the bug is fixed, but it works.
from https://github.com/mhammond/pywin32/issues/1151#issuecomment-360669440
append the 'pypiwin32_system32' path to your system PATH,
in a script this can be done like:
import os
sitedir='C:/where_ever/'
os.environ["PATH"]+=(';'+os.path.join(sitedir,"pypiwin32_system32"))
...
from powershell
$env:PATH="$PATH;C:\where_ever\pywin32_system32";
python.exe ...
for help on site dir, see What is python's site-packages directory?

Resources