I am new to ubuntu .I compiled a python script to an executable file in ubuntu 22.04 using pyinstaller (one file). It connects to a database by reading login credentials from a text file in the same directory.
such as ip address, password, port and username.The code is;
def remote_db_connector():
txtPath = Path.cwd().joinpath("text.txt")
myfile = open(txtPath)
x = myfile.read()
myfile.close()
return x
I collect the individual components by using split(). It works perfectly from the folder where the executable and text.txt file resides. When I created a desktop shortcut in ubuntu 22.04 it does not read the text file and the program does not run. The desktop short cut script is as follows;
[Desktop Entry]
Type=Application
Name=Mypro
Exce=/home/softwares/Mypro
Icon=/home/softwares/Myico.png
Terminal=true
StartupNotify=false
(I found it out by giving the shortcut script Terminal=true). Please help me.
2
Answers
Spell
Exec
correctly, maybe add aPath
to your desktop fileYou didn’t share
your .desktop file northe entire script, but from what I can see, it looks like you’re giving your script wrong directions by using Path.cwdTry it yourself.
Go into /path/to/yourscript.py and run your script as you normally do.
Then switch to the parent directory and try the same. It will fail.
pathlib.Path.cwd returns the directory from where the script was invoked, not its location.
exchange
with