'cfgrib' is not showing in xarray engine list, when the python code is packaged with pyinstaller to get exe file - pyinstaller

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!

Related

Module not installed

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.

PyInstaller EXE not executing

I have created an executable file from .py using PyInstaller. My python file contains the packages PySAM, pandas and os. Although the executable has been created successfully, while running it aborts before/while importing the packages and closes. I believe this is due to the PySAM package. I am looking for a solution such that the executable runs the entire code
Thanks in advance!

Pyinstaller doesnt package cv2 in jetson

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.

pyinstaller unable to fetch required module

I am trying to make a file uploader using pcloud. While doing so when I run my python code from Pycharm, it works perfectly fine. But when I convert it into exe using pyinstaller, it gives me "fatal error - failed to execute script"
here's my code
from pcloud import PyCloud
pc = PyCloud('myemail', 'mypassword')
print('connected !')
exact command used in pyinstaller was "pyinstaller --onefile myfile.py"
read about hidden imports, but dont know how to exactly add the module pcloud in my exe.
Any help would be appreciated !

PyInstaller ImportError

I have been experimenting with PyInstaller for a few days. My operating system is FreeBSD 10.4 and I use Python 3.6. When I issue this command from the terminal, it works all fine:
# pyinstaller my_script.py
But this command has an unprecedented side effect. When I write this:
if __debug__:
print("debug")
I get "debug" printed to the console, which suggests that PyInstaller compiles the script with debug symbols.
While searching for a solution to this problem, I found that running PyInstaller through the Python interpreter with the -O parameter would solve the problem:
[root#bsd-pwb ~]# /usr/local/bin/python3.6 /usr/local/lib/python3.6/site-packages/PyInstaller/__main__.py my_script.py
But this time, I get this:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/PyInstaller/__main__.py", line 21, in <module>
from . import __version__
ImportError: cannot import name '__version__'
What am I doing wrong here? How can I get PyInstaller to compile with "debug" set to "False"?
I recommend you trying your script exactly as it is but using a Python 3.5 Enviroment, there are so many publications where you can realize that pyinstaller is more stable with python 3.5 versions than 3.6. I had several errors as the one you are commenting and at the end they get solved just running my scripts on python<=3.5
From the docs you can actually get it working by using another method: set explicitely the PYTHONOPTIMIZE environment variable to a non-zero value, in your case:
PYTHONOPTIMIZE=1 pyinstaller myscript.py

Resources