pyinstaller - ModuleNotFoundError - pyinstaller

I have written 2 py files, located on the same root level. I am not using a Venv for this.
main.py
tickers.py
In my main.py file, I import tickers.
After running pyinstaller --onefile main.py , I get ModuleNotFoundError when running the exe file.
I thought pyinstaller could detect these dependencies but obviously not.
Has anyone solved this problem?
Thanks

Related

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

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!

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.

Problem Running Xgboost in Executable File

I am using a saved Xgboost model in a executable file created with PyInstaller. I setup a virtual env and downloaded Xgboost and ensured it ran but after I create the exe and run the exe I get an error about xgboost.core:
ModuleNotFoundError: No module nemed 'xgboost.core'
Actually I can't see any import problem with xgboost, first, make sure that you are using the latest version inside your env with pip install -U xgboost next try to add xgboost.core as a hidden-import and add xgboost's DLLs as data-files.
Suppose that your virtualenv is named env, use below command to generate your executable:
├───myscript.py
├───env
Code:
import traceback
try:
from xgboost import core
input("xgboost.core imported successfully!")
except Exception:
traceback.print_exc()
input("Import Error!")
Command:
(env) > pyinstaller myscript.py -F --hidden-import=xgboost.core --add-data "./env/xgboost/*;xgboost/"
--add-data "./env/Lib/site-packages/xgboost/VERSION;xgboost/"
The answer by #Masoud Rahimi did not work for me. What did was running pyinstaller using the --collect-all option:
pyinstaller -D <app_name>.py --noconfirm --collect-all "xgboost"
See this issue and the arguments in the pyinstaller manual

Adding the ibapi library to PYTHONPATH module in Spyder (Python 3.6)

I am trying to simply connect to the ibapi (Interactive Brokers API), but I am having some technical troubles with Spyder.
What I did so far:
I installed the latest version for Windows from here
I provided the following path to the PYTHONPATH manager in Spyder: C:\TWS API\source\pythonclient\ibapi afterwards I restarted Spyder
When I simply type import ibapi I get the same error message: ModuleNotFoundError: No module named 'ibapi'
What I am doing wrong here and how can I fix this simple error?
I don't use python very much but I'm pretty sure you have to install the ibapi. I never used the PYTHONPATH and mine works fine in Spyder and Jupyter. I'm using Anaconda.
I run the Anaconda prompt (just activates the conda environment) and navigate to the dir C:\TWS API\source\pythonclient and run python setup.py install
Then everything works. I think many python packages need to be installed like this.
note: That's not my install dir, I just copied yours. There may be a problem with a space in the path. Try renaming to C:\TWSAPI\... if you still have a problem.
Note: after python setup.py install, you might need to restart spyder. If doesn't help, then copy the newly-created ibapi folder to:
C:\Users\iuzeri\AppData\Local\Programs\Python\Python37-32\Lib\site-packages
or
C:\Program Files (x86)\Python37-32\Lib\site-packages
copy your ibapi here
C:/ProgramData/Anaconda3/Lib/site-packages/ibapi

'python' is not recognized as an internal or external command, operable program or batch file

I have created exe of python file using pyinstaller.From that file I am calling another python script.when I run my project on clean VM where python is not installed I am getting error like python is not recognised
import subprocess
import time
import sys
import os
print ("Hello")
python_path = "python"
args = [python_path,'test.py']
print(args)
subprocess.Popen(args)
time.sleep(100)
Where pyinstaller will look for python.When exe is frozen I found only python35.dll.How can i run python script from exe without installing python.
Download a standalone python package like WinPython-64bit-2.7.10.3 (This does not require to be installed with admin rights). You can unzip the files to a preferred directory.
From the WinPython-64bit-2.7.10.3 folder, you can copy the contents of the python source code folder (Eg : python-2.7.10.amd64, in this case) to the directory where you have placed exe file created using pyinstaller.
The python-2.7.10.amd64 (In this case) has the python.exe and other dependency files required for the subprocess call to run.

Resources