I have a software which I packaged in x86 processors using pyinstaller and it packages all libraries including cv2, however, when I try to package the same software in Jetson TX2, it doesn't package cv2 and throws error on executing the binary file:
OpenCV loader: missing configuration file: ['config.py']
The reason is cv2 comes preinstalled in TX2 at a different location (/usr/lib/python3.6/dist-packages). However, rest of the libraries which we self-installed are in (/home/mnauf/.local/lib/python3.6/site-packages) and maybe this is why pyinstaller fails to package it.
The pyinstaller tries to find cv2 at /home/mnauf/.local/lib/python3.6/site-packages and doesn't find there and correspondingly doesn't package, however cv2 imports fine if you do it with python. The reason why cv2 works fine with python is that I suppose python first tries to find a library in /home/mnauf/.local/lib/python3.6/site-packages and if unsuccessful, finds in /usr/lib/python3.6/dist-packages.
To solve the packaging problem, I tried the following methodologies and the errors discussed below all come when executing the binary file and don't come at the time of packaging:
Copying cv2 from /usr/lib/python3.6/dist-packages to /home/mnauf/.local/lib/python3.6/site-packages. It gives:
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
I try to copy cv2 directory from /usr/lib/python3.6/dist-packages to dist/main folder created by pyinstaller after packaging but I get the same Import error.
Adding the cv2 directory path as a data file in main.spec also only copies the folder to dist/main and hence gives the same Import error.
Adding the cv2.cpython-36m-aarch64-linux-gnu.so path only as a data file in main.spec gives Opencv loader error.
Adding the cv2 directory as a binary file path in main.spec gives the Import error.
Adding the cv2.cpython-36m-aarch64-linux-gnu.so path only as a binary file in main.spec gives the Opencv loader error.
Please help me with packing cv2. Thanks
I copied /usr/lib/python3.6/dist-packages/cv2/python-3.6/cv2.cpython-36m-aarch64-linux-gnu.so to /home/mnauf/.local/lib/python3.6/site-packages/ and then imported cv2 from python and checked its location where is it importing from by doing this:
import cv2
cv2.__file__
and it returned me the path I wanted i.e /home/mnauf/.local/lib/python3.6/site-packages/. Once confident that cv2 is indeed using the directory I want, I ran pyinstaller and did package the cv2 dependency.
Previously, I had copied the entire folder before creating its executables. This time I only copied the .so file, before creating executables and it worked.
And I think "before creating executables" is also the trick. You can't just copy the .so file to dist/main and expect it to work. Also, we concluded that giving .so file path as data file or binary file in main.spec doesn't work.
Related
I am trying to create an executable file from python code with 'Pyinstaller' package. The code runs in conda environment where the cfgrib selfcheck is good:
Found: eccodes v2.27.0.
your system is ready
However when the executable created by pyinstaller runs, the error is:
ValueError: unrecognized engine cfgrib must be one of: ['scipy','store']
I adde 'eccodes', 'python-eccodes', 'cfgrib', 'netcdf4' to the hidden imports, but no success. Does anybody have any idea to fix this issue!
I am writing a Dataframe to a Parquet file with Dask using the following code:
df.to_parquet('Filepath', engine='pyarrow')
Pyarrow module is required to run this code and it runs fine on my editor.
But when I package the code using Pyinstaller and try to run the .exe file I get the error
'pyarrow' not installed
How to fix this?
Note - I'm using the same python environment for Pyinstaller as well as my editor.
I've got code that loads a joblib file and works perfectly in my IDE. However when making an exe with pyinstaller it fails. This is some test code:
from joblib import load
print('imported joblib')
load('Repeat.joblib')
When running the exe it successfully imports load, but fails when reading the joblib file. The joblib file is a machine learning model build using scikit learn 0.22.1 and I have joblib 0.14.1.
I've tried everything I can think of. Pyinstaller initially failed with a recursion error but I fixed that using a spec file using
import sys
sys.setrecursionlimit(5000)
Any help?
A, I did find this post about people rolling back Joblib to v0.11 with some success. However that doesn't appear to have resolved your issue.
IT might be an issue with PyInstaller. The key might lie in your `hiddenimports'.
Bounty Source solution
I am trying to convert a python script which uses the webbot library for web automation.
As I tried to convert my running Python (3.6.5) script to an .exe file using pyinstaller I was getting an error that the path of the webbot module could not be found.
In order to overcome this problem I tried to specify the path of the module in the spec file, without success. An easier workaround suggests copying the downloaded folder webbot in the same folder where the .exe file is.
Its a very handy tool to use , i don't wanna ditch it .
In order for this to work you should not convert it as one file like this
pyinstaller --onefile file.py
but like this
pyinstaller file.py
After doing this the .exe could be launched without any problems.
An other error was coming because of trying to import webbot in my script. Probably this is a noob mistake, but one has to:
from webbot import Browser
I am attempting to convert a python file to an executable file. Easy enough right?
I used pyinstaller on a simple program that doesn't import anything. It worked like a charm. Then, I tried it with another dummy program with imported modules, (PyQt4, sys, matplotlib) that my actual program would have. Here I encountered problems.
This error appeared when I ran the application in the 'dist' folder pyinstaller created.
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
I found another site with a possible solution to this problem, but his situation wasn't exactly the same: http://code.activestate.com/lists/python-dev/118463/
This lead me to trying the QT designer that I downloaded earlier. Perhaps if I could convert the .ui file it produced into a .py file, I would be fine. I could use his solution and all would be well.
That's when I got this error:
File "C:\Anaconda3\Lib\site-packages\PyQt4\uic\pyuic.py", line 26, in module
from PyQt4 import QtCore
mportError: No module named 'PyQt4'
I should also probably mention that all the modules I have are through Anaconda 3
I thought installing pyqt in a conda... project? Would fix the problem. It didn't. To be honest I don't entirely know what those are for.
Now I'm entertaining the idea of just using the c++ files that QT designer makes instead of converting them and importing python to tell the gui what to do.
What do you guys think would solve the errors above?
Short solution / workaround:
In your python file import the missing module explicitly. In your case: import encodings.
Proper solution:
By importing every module separately so you might end up imorting many modules and submodules. In this case you need tell pyinstaller where to find the modules (e. g. using compile flags).