Pyinstaller: fatal error, failed to execute script - python-3.5

This is a recurring theme, distributing python code seams to be a non-ending issue (I have checked all related answers I could find on SO regarding this).
I have a script containing the following imports:
import tkinter as tk
from tkinter import *
from tkinter import messagebox as mbox
import pandas as pd
import time
import os
import glob
import base64
import matplotlib.pyplot as plt
from PIL import ImageTk, Image
plt.style.use('bmh')
It's basically a GUI containing several buttons (each launching a function that reads from a pandas data frame and shows a graph via a Matplotlib plot) and also a label with a logo.
I've tried my usual tweaking with pyinstaller (and also with and without the label image:
Simple (one file and without):
pyinstaller -F -w --noconsole -i icon.ico Script.py
Complex:
pyinstaller -F -w --noconsole --noupx -p C:\Users\USER\AppData\Local\Continuum\Anaconda3\Lib\site-packages --hiddenimport pandas --hiddenimport matplotlib --hiddenimport PIL --add-data "image.png;image.png" -i Fuji.ico --log-level=DEBUG Script.py
And every variation in between.
I have removed from Pyinstaller/loader/rthooks.dat the line 'PyQt4': ['pyi_rth_qt4plugins.py'] which is know to cause some issues.
I get the same error again and again:
Versions:
Pyinstaller 3.3.1 (/!\ Edit: I tried also with the dev version, same result)
Python 3.5.3
The results from the warn file in debug mode: https://pastebin.com/na0W4TGS
Does anyone have an idea on how to solve this?

I solved the issue by pasting the label image to the .exe folder and also the platforms folder from:
C:\'Users\USER\AppData\Local\Continuum\Anaconda3\Library\plugins

Related

PYINSTALLER exe not executing - blank terminal closes in 10 seconds

I am trying to make a small Python app to share with non-developers to help automate a small task.
The problem is that the .exe gets generated, and throws a mkl_intel_thread.1.dll issue. I then found the .dll and pasted it in the same folder as the .exe. Now the .exe runs without error, but closes without doing anything.
The python script runs fine and prints these when run separately (as a python file).
I read a lot on similar issues and did try many things, but nothing seems to work. Could anyone help me out, please?
Python code (prints pandas version, and then reads a file to print the number of records) :
I have some additional imports as I want to test their dependency for the actual program where they are used.
import requests
from glob import glob
from bs4 import BeautifulSoup
import pandas as pd
from datetime import datetime
from time import sleep
def View_model():
print(pd.__version__)
sleep(10)
data = pd.read_csv('test_data.csv', sep=';')
data_cnt = len(data)
print("Total records : ", data_cnt)
sleep(10)
if __name__ == "__main__" :
print("started")
View_model()
print("completed")
sleep(10)
Pyinstaller .exe generation command(s) :
pyinstaller -F --hidden-import 'numpy' --hidden-import 'requests' --hidden-import 'glob' --hidden-import 'bs4' --hidden-import 'pandas' --hidden-import 'datetime' --hidden-import 'time' --add-data "test_data.csv;." check1.py
Am I doing something wrong in the process, or is it something non-obvious that is going wrong?
Appreciate any help/leads. Note that I have the .dll file in the same folder as the .exe (see below)
I am using Miniconda (conda 4.10.3) & have Python 3.9.7

Vscode for python jupyter fail to show video

I'm trying to make a animation in the Jupyter of Visual Studio Code. The code is listed below.
import arviz as az
from IPython.display import HTML
from matplotlib.animation import FuncAnimation
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as st
...
...
...
anim = FuncAnimation(fig, update, frames=np.arange(bins.shape[0]),
init_func=init, blit=True, interval=20)
HTML(anim.to_html5_video())
However, the Jupyter fail to play the video on the Visual Studio Code. The result was shown in the picture below.
I'm also getting this issue. I've used this animation tutorial to confirm it was an VSCode issue and not my code, which I'd confirmed works in vanilla Jupyter.
I've installed JupyterLab for use with this code sample since it's easy enough to set up.
conda install -c conda-forge jupyterlab (or pip install jupyterlab)
jupyter lab
Executing the run command from the directory with your resources with default that as the run location of Jupyter so you shouldn't need to alter your code. Here's hoping they resolve this soon.

Pyinstaller with anaconda in spyder

So i wrote a little programm in python with use of tkinter. The repo is found here: https://github.com/Odatas/MeisterTools
I now want to create an exe so people only need to use the exe when they want to use the program. But the exe i create with pyinstaller doesnt work and throws the error:
Import Error: cannot import name 'travel' from 'main'
The cmd i opend to creat the exe is directly out of anaconda envoirment.
I cd into the folder where all the scripts are and then run it like this:
pyinstaller --onefile patrickstools2.py
I even tried to make every import an hidden import:
pyinstaller --onefile --hidden-import=init --hidden-import=main --hidden-import=checker --hidden-import=contact --hidden-import=dangers --hidden-import=droptable --hidden-import=importexcel --hidden-import=odatasfunctions --hidden-import=randomenpc --hidden-import=scrolltest --hidden-import=sonstiges --hidden-import=travel patrickstools2.py
that doesnt help either. I added the path through Anaconda to the PYTHONPATH variable...so it should be know in any way shape or form.
The complet code is in Anaconda. The Error gets thrown in the import section of the main file:
# page classes import
import os
try:
import Tkinter as tk
except ImportError:
import tkinter as tk
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
# page classes import
from . import travel
from . import contact
from . import dangers
from . import sonstiges
from . import randomenpc
I allready created an exe with pyinstaller from a previous version. But i made some changes to the structure of the programm. The run.py is only there because i work with spyder and as far as i know spyder needs it because else the import doesnt work correctly.

Can't open Pyinstaller's output file

SOLUTION:
The main issue was occurring due to ImageTk , this can be skipped by loading image using tkinter instead of PIL.ImageTk by using this command and using this object as normal you would do with PIL.ImageTk.
my_image = PhotoImage(file ="Image location here")
MAIN ISSUE:
I'm trying to pack these files into a single executable file using pyinstaller, but after compilation, the executable file doesn't run, don't know where the error is, files in the given link, and installation log in pictures
Command Used:
pyinstaller --onefile ui.py
Where ui.py is my driver script
Files:
https://github.com/RoyalEagle73/NIT-JSR-Result-Leecher/tree/master/GUI%20%2B%20Source%20v2.0/Source
Build Log( Images ):
What I've already tried
tried Cx_Freeze as an alternative but no application seems to open the output file.
here is what I'm importing overall in the whole program
from tkinter import *
from PIL import ImageTk, Image
import fb
from tkinter.ttk import Progressbar
import webbrowser
from tkinter import messagebox
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import re
from bs4 import BeautifulSoup
import time
I was not able to access the github link in your question, I think it did not get pasted properly. So I am unable to access your source files.
Try one of these:
pyinstaller --onefile --noupx ui.py
or
pyinstaller --debug --onefile --noupx ui.py
The pyinstaller uses UPX. The documentation for pyinstaller states the following:
PyInstaller looks for UPX on the execution path or the path specified
with the --upx-dir option. If UPX exists, PyInstaller applies it to
the final executable, unless the --noupx option was given. UPX has
been used with PyInstaller output often, usually with no problems.
Hope this helps.

ImportError: No module named 'matplotlib._path' when running a python script in apache2

I have been busting my head over this for a few hours now but I cant nail down the reason why this error occurs.
I am trying to run a simple python script in my apache2 server-
#!/usr/bin/python3.5
import cgi
import cgitb
cgitb.enable()
import sys
sys.path.insert(0, "/home/aswin/anaconda3/lib/python3.6/site-packages")
sys.path.insert(0,"/usr/local/lib/python3.5/dist-packages")
# HEADERS
print("Content-Type:text/html; charset=UTF-8")
print() # blank line required at end of headers
# CONTENT
import numpy as np
import os
# set HOME environment variable to a directory the httpd server can write to
os.environ[ 'HOME' ] = '/tmp/'
import matplotlib
# chose a non-GUI backend
matplotlib.use( 'Agg' )
import pylab
#Deals with inputing data into python from the html form
form = cgi.FieldStorage()
# construct your plot
pylab.plot([1,2,3])
print("Content-Type: image/png\n")
# save the plot as a png and output directly to webserver
pylab.savefig( sys.stdout, format='png' )
and I get the following error(screenshot attached)
I tried installing matplotlib via pip and also conda install.I also tried adding
sys.path.insert(0,"/usr/local/lib/python3.5/dist-packages") and
sys.path.insert(0, "/home/aswin/anaconda3/lib/python3.6/site-packages") as shown in the code above,
but nothing seems to fix this issue. I am running lubuntu btw.
Any help would be much appreciated. :)
screenshot of localhost
I had similar problem and it was fixed by upgrading the matplotlib

Resources