loguru ModuleNotFoundError when using pyinstaller - python

when building EXE with pyinstaller, the resulting exe file doesn't execute and the error 'ModuleNotFoundError: No module named 'loguru'' is shown.
Running the pythons script works without any issues.
didn't find any solution that worked so far on Stackoverflow

The simpler solution is to use --hidden-import=loguru along with the PyInstaller script. It will add modulename as import statement silently. Hooks are better if you want to specify which import needs what additional modules. --hidden-import is simpler as a one-shot or for debugging.

Related

py2exe strange missing modules

I think this is one of the many questions about missing modules and py2exe... anyway...
PylibUty is a local package located in C:\Dati\workspaces\PythonEclipse\APyLibUty\PyLibUty and referred in every .py file with:
import sys, os
sys.path.append(os.path.join(os.path.dirname("file"), '..'))
sys.path.append("C:/Dati/workspaces/PythonEclipse/APyLibUty")
from PyLibUty.pystr import randomString, insertStr
uuid is a Python package so I normally import it
_posixshmem I am not able to find what package I should install using pip/pipenv
resource: I installed both resource and pyresource using pip/pipenv bat nothing changed
What should I install or import to solve these problems?
This is the output produced running py2exe:
I did not find a solution to understand what modules I should add or install to clear the problems of py2exe, so I searched the web to find a different tool able to make exe files from Python sources. I found cx_freeze, actually it does not produce the errors I reported so at the moment I switched to cx_freeze. I will test it better but at the moment my problem is solved.

GDAL Import Error after freezing Python 3 script

I am trying to freeze a Python script that contains an import from osgeo but the executable fails with an ImportError: No module named '_gdal'.
I've stripped down my script to just one line:
import osgeo
When running in Python (version 3.3.3) all is well. I've tried freezing with cx_Freeze and py2exe. Both report that there is a missing module: ? _gdal imported from osgeo (among others) but successfully freeze the script. Then the exe fails with the above ImportError.
I've tried importing _gdal in python and it works. I tried manually including the osgeo module in the freezing options but still get the same error.
There is a similar question here:
Importing GDAL with cx_Freeze, Python3.4
but maybe this isn't a cx_freeze issue because it also happens with py2exe (it has experimental support for python 3 now).
Does anybody know how to fix this?
I found a fix. I edited the osgeo\__init__.py file and modified line 13 like this: import osgeo._gdal. This works but only if the module osgeo._gdal is manually included when freezing. #Thomas K Your solution does the same thing I guess.
Note that the same modification must be applied both at osgeo.ogr (line 18) and osgeo.osr (line 18) modules if they are needed (import osgeo._ogr and import osgeo._osr respectively). This means that these must be manually included when freezing as well. My freezing command now looks like this: python cxfreeze.py module1.py --include-modules=osgeo._gdal,osgeo._ogr,osgeo._osr.
Thanks #Thomas K for your help.

CefPython3, PySide, and cx_freeze: Can't get EXE working

I recently downloaded an installed the following:
Python 3.2.5
CefPython 3
PySide - for handling the GUI of my CEF-powered app
cx_freeze - to make my app distributable
Now, the first three work just fine. If I run pyside.py in CefPython's examples directory, the app starts as it should. However, if I try to freeze the app using the instruction below, the app compiles, but with errors.
Command line instruction
C:\Python32\Lib\site-packages\cefpython3\examples\PySide>cxfreeze pyside.py --target-dir bin --base-name Win32GUI --include-modules atexit,PySide.QtNetwork
Error
Missing modules:
? _gestalt imported from platform
? _posixsubprocess imported from subprocess
? cefpython_py27 imported from __main__
? cefpython_py32 imported from __main__
? win32api imported from platform
? win32con imported from platform
? win32pipe imported from platform
Then, when I try to run the app, I get the following:
ImportError: No module named cefpython_py32
Problem here is that I can't seem to include the module in the command line instruction. cx_freeze simply cannot find it.
What do I need to do to get cx_freeze to find CefPython?
Note: cx_freeze imports all the necessary DLLs, from the Qt framework, to CefPython itself. They are all there. Which begs the question as to why it knows where the DLLs are, but not the libraries. Also note that I'm a Python newbie. I'm sure there's a simple explanation as to what I need to do. I have a feeling I need to copy something into cx_freeze's dist directory - I just don't know what that file would be. I naturally assumed it would be a .pyc file, but there are none...
Update (whilst I was compiling this question):
I also tried the following instruction:
C:\Python32\Lib\site-packages\cefpython3\examples\PySide>cxfreeze pyside.py --target-dir bin --base-name Win32GUI --include-modules atexit,PySide.QtNetwork,cefpython3
Note the added cefpython3. Now, it compiles it, but the EXE throws a cx_freeze error: Cannot get zipimporter instance Also, the above errors persist, and so I think that using cefpython3 is wrong in this regard.

py2exe cannot import Module from other directory

I am bundling python source code with py2exe. The directory structure is as follows:
some_Mod.py
some_dir/another_dir/some_Mod.py
Inside the latter some_dir/another_dir/some_Mod.py I am trying to import the other Python Module with
from ..some_Mod import *
Using the import causes no problems with the python interpreter, but if I run the same constellation in the bundled package, I get an Exception:
ImportError: No module named some_Mod
Can somebody explain why?
Remark: Renaming the Modules is actually no problem, but I was just wondering, why py2exe cannot deal with this constellation.
If you have __init__.py files in each of those sub-directories then all import statements should work correctly.
Assuming that's not the problem, here's an excellent guide to importing best practices:
http://blog.habnab.it/blog/2013/07/21/python-packages-and-you/
In summary, never use relative imports - always absolute (see the link above for why).
Second (and I'm not entirely sure why), always keep your py2exe setup.py script in the exact folder where your main script is. I've tried modifying py2exe's 'script' option to allow my script to be somewhere else... but your exact problem happened to me. So, try making sure it is right where the main script is.
Finally, you can always give py2exe a little help. I usually have to add the root directory to the system path so the import statements are valid. Note, I'm not modifying sys.path in any of my application's code - only the py2exe script I use to build the exe.
At the top of my py2exe setup script:
import sys
sys.path.append(PATH_WHERE_PACKAGES_ARE)
# add any packages that need explicit importing here located in root directory:
import package1 # apparently it wasn't found...
import package2 # apparently same thing
Generally I don't import packages though, adding the project root where they exist usually is enough.
I'm not sure that py2exe now how to handle the from ..some_Mod import * syntax, check this to ensure that the some_Mod.py module is correctly packaged : python -m py2exe.mf -d some_dir/another_dir/some_Mod.py as explained in the py2exe FAQ

Pyinstaller no module named 'pyfiglet.fonts ' pyinstaller '

Hey i want to export my Python Selenium Projekt with Pyinstaller but every time when im trying to do this it wotrks but when i start the exe file i became this error:
ModuleNotFoundError: no module named 'pyfiglet.fonts'
to start pyinstaller i used this command:
pyinstaller --onefile SickoAIO.py
Without a little more information, it's hard to tell what's wrong. However, I'm going to assume some things you haven't stated and provide some ideas:
Assuming SickoAIO.py works fine before you try to use pyinstaller, sometimes if in your Python code you only imported the more general module:
import pyfiglet
but need to use pyfiglet.fonts, a "hack" for it to work in pyinstaller could be to make the import more specific:
import pyfiglet.fonts
I've not used pyfiglet, but this hack worked for me with the numpy module, for example.
Another thing that has helped me troubleshoot a similar issue with numpy, scipy, etc. is updating the versions of the module and/or pyinstaller
It's possible you may need to use hooks, especially since it seems like pyfiglet may not play well with pyinstaller. This is explained specifically for pyfiglet here:
https://hugomartins.io/essays/2019/06/pyinstaller-pyfiglet-trouble/
I didn't try it, and it looks like you may need to click on more links in that webpage as well as learn more about how hooks work in pyinstaller (https://pyinstaller.readthedocs.io/en/stable/hooks.html?highlight=hook) to understand the full issue.

Categories

Resources