Failed to execute script due to unhandled exception: No module named ttkwidgets - pyinstaller

I created an executable from a py file that used ttkwidgets
import tkinter as tk
import work_logger_database
from ttkwidgets.autocomplete import AutocompleteEntry
root = tk.Tk()
root.geometry('600x300')
items = work_logger_database.show_all()
stored_projects_list = list(set([items[i][2] for i in range(len(items))]))
#or:
#example_list = ['Hello', 'World']
project_entry = AutocompleteEntry(root, completevalues=stored_projects_list)
project_entry.grid(column=0, row=1, sticky='W')
root.mainloop()
and when I open the exe I get what is shown in this image
I also got a warning:
WARNING: Several hooks defined for module 'numpy'. Please take care they do not conflict.
I'm not sure if that's relevant
I tried a solution in creating the exe that didn't work:
pyinstaller work_logger.py --onefile -w --hidden-import=ttkwidgets --hidden-import=ttkwidgets.autocomplete
I also tried:
pyinstaller work_logger.py --onefile -w --hidden-import=ttkwidgets

Had the same ModuleNotFoundError: 'ttkwidgets' creating an executable of one of my scripts.
Worked after (re-)installing ttkwidgets on my system:
pip install ttkwidgets

Related

Can't import cv2 (opencv-python) on apple M1

I want to run a script on python that requires opencv-python. I'm working on a Mac. Based on other questions/answers here it seems the issue might be related to the M1 chip
I installed the latest version using the pip install command. Using pip list , I see that the installation was successful [opencv-python version 4.5.5]
now I encounter this error when I try to import cv2 on python3:
Traceback (most recent call last):
File "< stdin >", line 1, in < module >
ImportError: dlopen(/Users/maha/opt/anaconda3/lib/python3.9/site-packages/cv2.cpython-39-darwin.so, 0x0002): Library not loaded: #rpath/liblapack.3.dylib
Referenced from: /Users/maha/opt/anaconda3/lib/libopencv_core.4.5.5.dylib
Reason: tried: '/Users/maha/opt/anaconda3/lib/liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/lib/liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/lib/python3.9/site-packages/../../liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/lib/python3.9/site-packages/../../liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/bin/../lib/liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/bin/../lib/liblapack.3.dylib' (no such file), '/usr/local/lib/liblapack.3.dylib' (no such file), '/usr/lib/liblapack.3.dylib' (no such file)
If I try to import on python (the older version) this is the error I get:
ImportError: No module named cv2
I tried to move the directory (opencv-python-4.6.0.66) to my anaconda3 library (where it looks like it is searching for it) with no success.. hope someone will be able to guide me

Darkflow without GPU on Jupyter-Notebook - Simple Code Required

I am unable to setup & run a simple darkflow program. Infact can't even configure darkflow library:
from darkflow.net.build import TFNet
==> ModuleNotFoundError: No module named 'darkflow'
My Target is to run the following program:
from darkflow.net.build import TFNet
import cv2
options = {"model": "cfg/yolo.cfg", "load": "bin/yolo.weights", "threshold": 0.1}
tfnet = TFNet(options)
imgcv = cv2.imread("./test/dog.jpg")
result = tfnet.return_predict(imgcv)
print(result
Please suggest steps so that I could configure darkflow on Jupyter Notebook (with no GPU) and run the above code
Fixed by creating the file in ipynb file in darkflow directory (downloaded from github) and executing the following from the notebook:
!python3 setup.py build_ext --inplace
!pip install -e .
!pip install .

How to resolve: ImportError: cannot import name 'HttpNtlmAuth' in python3 script?

I have installed both requests and requests_ntlm modules using "sudo python3 -m pip install requests" (and requests_ntlm respectively) and both installs were successful.
When I then attempt to do "from requests import HttpNtlmAuth", I get an error stating "cannot import name 'HttpNtlmAuth'. I do not get this error on my "import requests" line.
When I do a "sudo python3 -m pip list", I see both are installed and are the latest versions.
I've not encountered this error before, only "cannot import module", so I'm unfamiliar with how to resolve this.
EDIT 1: Additional information. When I run this script from command line as "sudo", it works. Because I am running my python script from within a PHP file using "exec", I don't particularly want to run this as a root user. Is there a way around this, or possibly running the exec statement with sudo?
the HttpNtlmAuth class is in the requests_ntlm package so you'll need to have:
import requests
from requests_ntlm import HttpNtlmAuth
Then you'll be able to instantiate your authentication
session = requests.Session()
session.auth = HttpNtlmAuth('domain\\username','password')
session.get(url)

Python/R ctypes library error: "OSError: lib/libRrefblas.so: undefined symbol: xerbla_"

Firstly, I'm a newbie R, AWS and python guy. So I'm trying to get a python script with embedded R code running in AWS Lambda using rpy2. I created a Lambda package on an EC2 instance following the instructions here (modified for using python 3.4). It seems that there is something funky happening with loading the R libs using ctypes, as per the following error received in the console:
OSError: lib/libRrefblas.so: undefined symbol: xerbla_
The test file (py_test.py) looks like this:
import os
import ctypes
for file in os.listdir('lib'):
if os.path.isfile(os.path.join('lib', file)):
ctypes.cdll.LoadLibrary(os.path.join('lib', file))
os.environ["R_HOME"] = os.getcwd()
os.environ["R_USER"] = os.path.join(os.getcwd(), 'rpy2')
os.environ["R_LIBS"] = os.path.join(os.getcwd(), 'library')
os.environ["LD_LIBRARY_PATH"] = os.path.join(os.getcwd(), 'lib')
import sys
sys.path.append(os.path.join(os.getcwd(),'rpy2'))
import rpy2
from rpy2 import robjects
def test_handler(event, context):
robjects.r('''
f <- function(r, verbose=FALSE) {
if (verbose) {
cat("I am calling f().\n")
}
2 * pi * r
}
print(f(3))
''')
test_handler(None,None)
I have lib/libRrefblas.so in my virtual environment. I have scoured google looking for answers but have come up empty. Any suggestions would be greatly appreciated!
If you can get the traceback, that could help, but I suspect the problem is that it's looking for xerbla_ in the wrong place. Is xerbla_ defined in the path to RLIBS? Maybe in libR.so?
Turns out the BLAS that ships with R is corrupt. Your best bet is to make sure that BLAS and Lapack are installed on the machine you are building R on and see if you can get it to build with those libraries instead.
So steps would be to uninstall R, then run
yum -y install lapack-devel.x86_64 lapack.x86_64
yum -y install blas -devel
yum -y install R.x86_64
Check to see if it has still installed with libRrefblas.so. If it has - try deleting that file and see if it will default to the system BLAS. If you get a error because it is still looking for libRrefblas.so
rm lib/libRrefblas.so
cp /usr/lib64/libblas.so.3 lib/
mv lib/libblas.so.3 lib/libRrefblas.so

How to Export a python project as an executable file? Project is a browser based one

I have a python project which has to be exported in to an executable file so that it can be used in other systems as well. The project has its UI in a browser and runs on localhost.
So far I have tried PyInstaller and cx_Freeze but to no success. I encountered some errors with PyInstaller which I was unable to solve and I switched to cx_Freeze. I was able to freeze the scripts and create a .exe file. But when I open(double click) the .exe file, I get nothing. Not even an error message. I tried running it from command prompt as well, but there too I got no message or output.
Can anyone suggest how my objective can be achieved? Or something needs to be checked?
Here is my setup.py
import sys
import os
from cx_Freeze import setup, Executable
base = None
#if sys.platform == "win32":
# base = "Win32GUI"
os.environ['TCL_LIBRARY']="C:\\Users\\M******\\AppData\\Local\\Continuum\\Anaconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY']="C:\\Users\\M******\\AppData\\Local\\Continuum\\Anaconda3\\tcl\\tk8.6"
setup ( name = "Network Analysis",
version = "0.1",
description = "Network Analysis Project",
options = { "build_exe": { "packages" : ['encodings','asyncio','pandas','numpy','geopy','networkx','configparser','json']}},
executables = [Executable("run.py",base=base)])

Resources