return error of 126 when compiling with idle 3.5 - python-3.x

subprocess.call('/Users/siddarthkrishnan/Desktop/Lion.jpg', shell = True)
126 giving me this in python 3.5 return of 126.
Why is the file not opening? It is giving return error 126.

Based on the path you pasted I assume you are on Windows. subprocess.call tries to invoke your jpg file as an executable (like *.exe, *.bat etc.) and fails because it isn't an executable. This is not a bug, this is the correct behavior.
If you want to launch the Windows Photo Gallery (or whatever program is set for the *.jpg file extension in your file associations), you can use os.startfile like this:
import os
os.startfile('/Users/siddarthkrishnan/Desktop/Lion.jpg')
Note: this solution works only on Windows.

Related

Executable file made using Pyinstaller doesn't start

I want to convert the following sample python program into an executable file:
import os
print(os.getcwd())
To convert it into an executable I have used Pyinstaller:
pyinstaller app.py --onefile
And the EXE file is getting generated in the dist folder, but when I run it, it launches and immediately closes, and the expected print statement is not even displayed.
What could be the issue?
It does prints the statement, but just after printing it the code ends. You can add input() or use time.sleep(seconds) to make your program wait until you press a key or any particular number of seconds respectivly.
To check if your code(without the advice i have given) prints, start that python file in your command line.

TkDnd working in Spyder but gives error after converting .exe

I am creating one application which sorts files and merges them based filename. I needed filepaths when i drop files from file browser to my widget's listbox. For Tkinter i installed TkDnd. I followed instructions from How to Install and Use TkDnD with Python 2.7 Tkinter on OSX? and it worked for me. I am using Anaconda and i paced folders in C:\Users\Anaconda3\tcl and C:\Users\Anaconda3\Lib\site-packages. I am using Spyder and python 3.7. I made executable from below command:
pyinstaller --onefile -w PDF_Merger.py
After opening file it gives me error:
Fatal error ".py failed to execute"
I know this problem is regarding linking TkDnd.
I have tried making executable with --onedir and it still gives me error. But after copying tkdnd2.8 to dist it works.
Here is my code using TkDnd:
from TkinterDnD2 import *
widget = TkinterDnD.Tk()
filesinfileslist = Variable(widget)
FilesShow = ReorderableListbox(widget, font=('aerial',12), height = 23 , width = 45, listvariable = filesinfileslist, selectmode = EXTENDED)
FilesShow.place(x=10, y=40)
FilesShow.drop_target_register(DND_FILES)
FilesShow.dnd_bind('<<Drop>>', drop)
drop method takes only pdf files and sets it to listBox.
As of now it works in spyder but .exe file gives me error. Can anyone show me how to resolve this issue or if i made some errors in code?
I resolved this issue with adding files from tkdnd2.8 folder with --add-data attribute while generating executable with pyinstaller. I was able to create it with onefile.
This post is already a few years old but I got to it when I looked for my problem. In the end I solved it like this:
pyinstaller --onefile --add-data=C:\ProgramData\Anaconda3\tcl\tkdnd2.8\;' myfile.py

How to create a Python Executable that can run other python-files stored in a folder?

Is it possible to create a Python Executable file (using PyInstaller or similar) that can in its code access other Python-files stored in a specific folder?
The reason for that it MUST be an Executable is that the script sometimes must be run from computers that has not it's own Python installed. I have no problem creating an executable (with PyInstaller for example) and they work fine. The python script itself loads various kinds of data into a database. But everytime there is a new kind of data that has to be loaded into the database I have to recreate the hole exe-file. I'm looking for a way for the executable to access python-files (with Data Load Instructions) so that the actual pyton load-files can be altered instead of the exe-file.
I have tried to find a solution using this:
import os, time
from subprocess import call
for file in os.listdir('.'):
if file == 'loadInstructions.py':
call(['python', file])
print(file)
cwd = os.getcwd()
print(cwd)
input('To EXIT progran press ENTER.')
time.sleep(3)
It works running it from a python editor but when I turn this into an exe-file it does not. If I creat an exe-file with "call(['python', file])" commented out the rest works which I interpret that the exe-file can find the file in question but not run it.
I would be gratefule for any help.

FatalError failed to execute script. PyQt5

I know that questions have already been raised on this topic, but I believe that all decisions were strictly individual. The essence of the problem:
There is a calculator.py script and a kalkulator.py These files are in the same directory, the calculator file is executable, this is the file that I convert into an EXE using PyInstaller. Inside the file, I import several PyQt5 libraries, and the second file is Python: from kalkulator import *
The second file kalkulator.py contains the GUI of the program created with QtDesigner
When i run the command pyinstaller --onefile --debug calculator.py everything goes fine.
But when I run the EXE program file in debug mode, I see the following error:
The photo shows that the following error occurs.
"DLL Load Failed: The specified procedure could not be found."
I can assume that the problem is that when assembling, PyInstaller does not see the file kalkulator.py it contains a graphical interface.
What can you say about this problem, how do you think you can solve it?
I use:
Python 3.5
PyQt5
PyInstaller 3.3.1
I managed to solve my problem! I changed the version of Python 3.5.0 to 3.6.0, and also reinstalled PyQt5.

System Error when running PyQt4's loadUi()

I'm pretty new to Qt, Python and their combinations. I'm currently writing a QGIS plugin in python (I used QtCreator 2.1 (Qt Designer 4.7) to generate a .ui-file and am now trying to use it for a Quantum GIS plugin that's written in Python 2.5 (and running in the Quantum GIS Python 2.5 console)).
I am running into trouble when loading the ui-file dynamically when the program runs the loadUi() function. What throws me off is that the error occurs outside my script. Does that mean, I'm passing something wrong into it? Where does the error come in? Any hints on what could be wrong?
code_dir = os.path.dirname(os.path.abspath(__file__))
self.ui = loadUi(os.path.join(code_dir, "Ui_myfile.ui"), self)
This is the Error Code I am getting (minus the first paragraph):
File "C:/Dokumente und Einstellungen/name.name/.qgis/python/plugins\myfile\myfile_gui.py", line 42, in __ init __
self.ui = loadUi(os.path.join(code_dir, "Ui_myfile.ui"), self)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic__init__.py", line 112, in loadUi
return DynamicUILoader().loadUi(uifile, baseinstance)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\Loader\loader.py", line 21, in loadUi
return self.parse(filename)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 768, in parse
actor(elem)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 616, in createUserInterface
self.traverseWidgetTree(elem)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 594, in traverseWidgetTree
handler(self, child)
File "C:\PROGRA~1\QUANTU~1\apps\Python25\lib\site-packages\PyQt4\uic\uiparser.py", line 233, in createWidget
topwidget.setCentralWidget(widget)
SystemError: error return without exception set
I'm not sure of what could be causing this precise problem, but using .ui files directly has never worked well for me - instead I compile them to python code using pyuic4 (should be in your path if your PyQt4 site-packages are correctly configured. The syntax is along the lines of :-
pyuic4 -o <python output> -x <uic input>
-: resource files can similarly be converted to (not so human-readable) python using :-
pyrrc4 -o <python output> <qrc input>
-: You can then import that python file as a module, not to mention that reading its code can give you clues on how to fiddle with the layout at runtime.
The other upside of this is that you are not having to parse xml at runtime - importing a python module is far quicker and you are not likely to change the ui anywhere near as often as you run the script. If you do find yourself in this situation you can just create a batch to run these before your script/application.
This is the method I use in conjunction with pyInstaller to deploy scripts that will 'just run' on XP, Vista and Windows 7 without modification, and I generate the python modules just before compiling with pyInstaller, so it can be a real time saver.

Resources