Unable to find C:\nltk_data while creating executable using pyinstaller - python-3.x

I am trying to create executable python file using pyinstaller, but while loading hooks, it shows error like this,
24021 INFO: Removing import of PySide from module PIL.ImageQt
24021 INFO: Loading module hook "hook-pytz.py"...
24506 INFO: Loading module hook "hook-encodings.py"...
24600 INFO: Loading module hook "hook-pandas.py"...
25037 INFO: Loading module hook "hook-lib2to3.py"...
25131 INFO: Loading module hook "hook-lxml.etree.py"...
25131 INFO: Loading module hook "hook-pycparser.py"...
25396 INFO: Loading module hook "hook-setuptools.py"...
25506 WARNING: Hidden import "setuptools.msvc" not found!
25506 INFO: Loading module hook "hook-distutils.py"...
25521 INFO: Loading module hook "hook-nltk.py"...
Unable to find "C:\nltk_data" when adding binary and data files.
I have tried coping nltk_data from Appdata to C drive. but same error.

This answer worked for me... it modifies the code in hook-nltk.py to only include the path if it exists.
hook-nltk.py can be found in your PyInstaller location within the hooks folder (something like <'path-to-python-installation'>\Lib\site-packages\PyInstaller\hooks)

I have been working on this issue for a few days not and don't have hair left. For some reason nltk and pyinstaller do not work well together.
So my first solution to this issue is to use something other than nltk if it is possible to code the solution without nltk.
If you must use NLTK, I solved this by forcing the nltk_data path into datas.
Locate your nltk_data path. Mine was in
C:\Users\user-name\AppData\Roaming\nltk_data
In hook-nltk.py (within pyinstaller directory) I commented out and added lines to look like this.
import nltk
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('nltk', False)
'''
for p in nltk.data.path:
datas.append((p, "nltk_data"))
'''
datas.append(("C:\\Users\\nedhu\\AppData\\Roaming\\nltk_data", "nltk_data"))
hiddenimports = ["nltk.chunk.named_entity"]
There is a deeper problem with pyinstaller looping through the datas list of paths, but this solution works as a patch.

I solved the problems editing the pyinstaller nltk-hook. After much research, I decided to go it alone in the code structure. I solved my problem by commenting on the lines:
datas=[]
'''for p in nltk.data.path:
datas.append((p, "nltk_data"))'''
hiddenimports = ["nltk.chunk.named_entity"]
What's more, you need to rename the file: pyi_rth__nltk.cpython-36.pyc to pyi_rth_nltk.cpython-36.pyc . This file have 1 more underline. Warning with the python version.

Related

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

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```

PyQt5 application is not working (just cmd flashing) when built with PyInstaller or py2exe, missing dll's

I've created a script in python that is using PyQt5. Now everything works when I'm launching the file from my editor - Studio Code in this case.
I'm having a problem when I try to deploy an exe using PyInstaller or py2exe it gives me error on missing dll's when it's building. It still finishes building anyway, but when I try to run the exe file the cmd window just flashes for a brief moment and nothing more happens.
I suppose this is due to missing dll's and if not than I have to sort this out first anyway.
I've tried searching for the dll's I'm missing on my computer and some I couldn't find at all e.g. Qt53DInput and one I could find in what I suppose is application made in Qt - Qt5Multimedia .
I'm currently using python 3.7.4 which I've already tried reinstalling. I think I didn't try to reinstall PyQt5, should I try doing that?
from PyQt5 import QtWidgets, uic, QtGui, QtCore, QtQuick
import sys
import os.path
import datetime
import shutil
I guess the only important part of my script in this case are the imports, so I've included them here.
python -m PyInstaller --paths C:\Users\bonana\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\PyQt5\Qt\bin my_code.py
Somewhere I've read that it's good idea to include this path, but since the dll are not to be found anywhere, including this folder, then obviously didn't help at all.
This is the warning about the dll's I'm getting:
Looking for dynamic libraries
32805 WARNING: lib not found: Qt5MultimediaQuick.dll dependency of C:\Users\bonana\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyQt5\Qt\qml\QtMultimedia\declarative_multimedia.dll
58554 WARNING: lib not found: Qt53DInput.dll dependency of C:\Users\bonana\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyQt5\Qt\qml\QtQuick\Scene3D\qtquickscene3dplugin.dll
58844 WARNING: lib not found: Qt53DAnimation.dll dependency of C:\Users\bonana\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyQt5\Qt\qml\QtQuick\Scene3D\qtquickscene3dplugin.dll
58989 WARNING: lib not found: Qt53DRender.dll dependency of C:\Users\bonana\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyQt5\Qt\qml\QtQuick\Scene3D\qtquickscene3dplugin.dll
59284 WARNING: lib not found: Qt53DLogic.dll dependency of C:\Users\bonana\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyQt5\Qt\qml\QtQuick\Scene3D\qtquickscene3dplugin.dll
59440 WARNING: lib not found: Qt53DCore.dll dependency of C:\Users\bonana\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyQt5\Qt\qml\QtQuick\Scene3D\qtquickscene3dplugin.dll
60365 WARNING: lib not found: Qt53DQuickScene2D.dll dependency of C:\Users\bonana\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyQt5\Qt\qml\QtQuick\Scene2D\qtquickscene2dplugin.dll
60680 WARNING: lib not found: Qt53DRender.dll dependency of C:\Users\bonana\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyQt5\Qt\qml\QtQuick\Scene2D\qtquickscene2dplugin.dll
60992 WARNING: lib not found: Qt53DCore.dll dependency of C:\Users\bonana\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PyQt5\Qt\qml\QtQuick\Scene2D\qtquickscene2dplugin.dll
84256 WARNING: lib not found: api-ms-win-core-winrt-l1-1-0.dll dependency of C:\Users\bonana\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\PyQt5\Qt\bin\qt5bluetooth.dll
84545 WARNING: lib not found: api-ms-win-core-winrt-string-l1-1-0.dll dependency of C:\Users\bonana\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\PyQt5\Qt\bin\qt5bluetooth.dll
Maybe it's not complete answear to why PyInstaller or py2exe is not working, but I've found way to deploy my exe properly. I've used fman build system. It didn't work right off the bat though. I had to install windows 10 sdk and make small change to my code:
QFileDialog.getOpenFileName(appctxt)
This no longer worked, because for some reason it needed to be changed to:
QtWidgets.QFileDialog.getOpenFileName(appctxt)
Other than that everything including creation of an installer worked without a problem.

FatalError failed to execute script. PyQt5

I know that questions have already been raised on this topic, but I believe that all decisions were strictly individual. The essence of the problem:
There is a calculator.py script and a kalkulator.py These files are in the same directory, the calculator file is executable, this is the file that I convert into an EXE using PyInstaller. Inside the file, I import several PyQt5 libraries, and the second file is Python: from kalkulator import *
The second file kalkulator.py contains the GUI of the program created with QtDesigner
When i run the command pyinstaller --onefile --debug calculator.py everything goes fine.
But when I run the EXE program file in debug mode, I see the following error:
The photo shows that the following error occurs.
"DLL Load Failed: The specified procedure could not be found."
I can assume that the problem is that when assembling, PyInstaller does not see the file kalkulator.py it contains a graphical interface.
What can you say about this problem, how do you think you can solve it?
I use:
Python 3.5
PyQt5
PyInstaller 3.3.1
I managed to solve my problem! I changed the version of Python 3.5.0 to 3.6.0, and also reinstalled PyQt5.

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.

use nodebox as a module for python 3.5

I'm trying to import everything from nodebox.graphics into my python 3.5 code but I get errors:
ImportError: No module named 'bezier'
To mention, this module exists in nodebox/graphics. As I searched in python documentations, I have to add the nodebox and pyglet folders into the directory of my code but that did not work.
I also didn't succeed in adding them to system directories.
How can I solve the problem and run my code properly?
P.S. I'm currently using ubuntu 16.04 if it matters.
I had the same error. Placing all the .py files except (and this is important) the __init__.py file in the main libraries folder fixed it for me. The final path should look like ~/lib/python3.5/site-packages/bezier.py

Resources