My Tkinter exe App realized can't find my module - python

i create an app in Python with Tkinter. When I execute this code with Pycharm it works, but after creating the exe i get this error. I load the error screen
I used pyinstaller to create the exe: pyinstaller.exe --onefile --windowed --icon=icona_interfaccia.ico v2_tkinter_robot_gui.py
The app code is divided into four folders, called:
Vision_Code
Interface_Code
Manual_movements_Code (Codice_Manuale)
Kinematics_Code (Codice_Cinematica)
All this four folder are saved in one call Code.
The v2_tkinter_robot_gui.py is the main file, where all the codes I wrote converge and it is saved in the folder called Interface_Code.
To import my modules I use the following wording:
from Codice_Manuale.Movimentazione_manuale import moveJabs, moveJ
#from Codice_Cinematica.cinematica_pallettizzatore import *
#from Codice_Manuale.funzioni_gestione_meccanica import aggiusta_zeri, workspace,
finecorsa_angoli, home_braccio
from Codice_Visione.movimento_ciclo_completo_visione import *
from Codice_Visione.movimento_immediato_visione import *
I had already created an exe on another machine that I no longer have. On this one it worked without problems.
Thanks in advance for the help

Related

Import errors with Jython/opentripplanner even though the file is listed in the directory

I'm trying to use otp to generate some journeys to a list of destinations. I'm starting with the script outlined in this post: https://stackoverflow.com/a/33222627
However, this first import keeps failing.
#!/usr/bin/jython
from org.opentripplanner.scripting.api import OtpsEntryPoint
For context, OtpsEntryPoint is a java file.
I get the following error: ImportError: No module named opentripplanner
But in the terminal, org/opentripplanner/scripting/api/OtpsEntryPoint.java definitely exists
I've tried running the script from other folders using sys.path to specify the import folder but this hasn't worked.

Python/Linux/Streamlit: executing subprocess for linux script

I'm a bit turned around on how to execute a shell script file in a Linux environment via Python's subprocess command in Streamlit. Any assistance on what I'm missing is appreciated.
I'm using a shell script called 0_texts.sh to run Pylanguagetool for a grammar check of one text file and return corrections in another text file, like so:
cd /home/user/dir/TXTs/
pylanguagetool text_0.txt > comments_0.txt
This script runs correctly in the Linux terminal, writing a comments_0.txt with appropriate grammar checks from text_0.txt.
I need to create a Python/Streamlit app that runs these shell scripts. In attempting to run this shell script, I've written script.py below:
import os
import subprocess
import sys
subprocess.run(['bash','/home/user/dir/Scripts/0_texts.sh'])
I then run script.py in Streamlit via the code below, keeping with Streamlit's documentation on using subprocess here.
import streamlit as st
import os
import subprocess
import sys
def app():
button1 = st.button("Click me")
if button1:
p = subprocess.run([f"{sys.executable}", "/home/user/dir/pages/script.py"])
st.write(p)
When I execute the script.py via Streamlit, the 0_txts.sh script executes, writing comments_0.txt in the correct directory and providing the following traceback: CompletedProcess(args=['/usr/bin/python3', '/home/user/dir/pages/script.py'], returncode=0). However, the comments_0.txt output contains the error input file is required, as if it can't properly access or read text_0.txt. I've tinkered around trying to find the problem, but have hit a brick wall.
Any suggestions on what I'm missing, or paths forward? Any help greatly appreciated.

How to import a python file inside a folder?

Im having trouble importing a python file that is in the seme directory but on a folder: ./subproject1/subproject1.py
Error:
File "/home/ubuntu4/Downloads/ProjectX/main.py", line 4, in
import subproject1.subproject1
ImportError: No module named subproject1.subproject1
The project looks like this:
/home/ubuntu4/Downloads/ProjectX
-/subproject1
- subproject1.py
main.py
And I import like this on python:
import sys
import os
import multiprocessing
import subproject1.subproject1
I have runned this from my windows PC and it works perfectly and from my ubuntu pc it isn't working, some suggestions?
I think it's a bug since I restarted the computer, without any changes and the problem was solved, when working with a virtual environment in a virtual machine it may have generated a bug

Cannot open .exe after pyinstaller convert

Running my GUI application created in PyQt5 using any IDLE or the file.py is running perfectly, however, when I converted the .py to .exe using Pyinstaller
I get an error every time I try to run the .exe file for some reason a small command window pops with an error and immediately disappear I screenshot the error before it closes. Any Idea Thanks in advance
Error image.
I tried to execute different commands for pyinstaller but no luck.
<pyinstaller filename -F >
<pyinstaller filename -onefile >
<pyinstaller filename >
It's an app over 900 lines and I cannot upload all of that but I think according to the error first lines.
The error occurs so here are the lines of code.
The problem is within importing modules I believe.
from PyQt5.QtWidgets import QWidget
from PyQt5 import QtCore, QtGui, QtWidgets
from datetime import datetime
import time
import os, sys #importing system modules
class Ui_MyTrophiesWindow(object):
class save_txt_file(QWidget):
def GetSaveFile(self):
path = QFileDialog.getSaveFileName(self,"Save MyTrophies.txt here", "MyTrophies", "*.txt")
working_path = os.path.abspath(__file__)[0:-13]
file = open(str(working_path) + "Txtpath.dat", "w+")
for i in path:
file.write(str(i))
file.close()
It is very common that sometimes PyInstaller won't recognize all Qt5 dependencies especially QT core DLLs. A simple way is to just locate that file on your current Python path and feed it with add-data flag in PyInstaller. Also, I suggest you not to use upx with PyQt as it may corrupt some DLLs:
pyinstaller --noupx -F --add-data "<Python_path>/Lib/site-packages/PyQt5/Qt/bin/Qt5Core.dll;./PyQt5/Qt/bin" script.py
To verify the answer suppose below example:
import traceback
import os
import sys
def func():
from PyQt5.QtWidgets import QWidget
from PyQt5 import QtCore, QtGui, QtWidgets
try:
if getattr(sys, 'frozen', False):
print(sys._MEIPASS)
func()
print("Import OK!")
except Exception:
traceback.print_exc()
input()
After you run the executable you would see the path for Pyinstaller (something like C:\Users\User\AppData\Local\Temp\_MEI90202), go to this path and search for the Qt5Core.dll and check if it is there.
I had look your error and according to me, I think you need to (re)install Qt5core.dll module and to add it in the site-package/PyQt5/init.py path. You can download the dll file here:
http://www.telecharger-dll.fr/dll-Qt5Core.dll.html
Good evening
Make sure that you have all the items of that app in the correct folder. Let me put an example that happened to me days ago:
I had an app with a folder named "options" that had 3 files (2 icons for my buttons ui and a .ini file). When I created the pyinstaller version of my program I assumed that it would somehow copy those files and pack them inside the --onefile file or into the dist folder (if not --onefile command was used). Nope, it didn't.
After scratching my head for hours, I just copied the options folder from my source files and pasted it next to my --onefile file (or inside the dist folder).
After that, my app works without issues. So... make sure it has all the files it needs in the correct folders.

python: py2exe paramiko showing no results

I am using python 2.7.11 on Windows 7 64bit, I am facing a problem with py2exe when I import paramiko module, the .exe file runs but does not show any results, after executing it closes immediately knowing that i did not get any error during the conversion.
import paramiko
print raw_input("press enter to exit")
the setup.txt file:
from distutils.core import setup
import py2exe
setup(console=['test.py'])
I have found that in the "dist" folder there are some dll files such as API-MS-Win-Core-ErrorHandling-L1-1-0.dll - API-MS-Win-Core-LibraryLoader-L1-1-0.dll - API-MS-Win-Core-LocalRegistry-L1-1-0.dll, such files I don't usually face them on another machine, so could anyone help please.
I was able to solve this after importing some modules:
import appdirs
import packaging
import packaging.version
import packaging.specifiers
import packaging.requirements
hopefully that could be useful for someone.

Categories