Search code examples
pythonlinuxubuntushortcutpyqt6

Desktop shortcut in ubuntu not working (not reading a text file in the source folder)


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 create a desktop shortcut in Ubuntu 22.04 it does not read the text file and the program does not run. The desktop shortcut 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.


Solution

  • Spell Exec correctly, maybe add a Path to your desktop file

    [Desktop Entry]
    Type=Application
    Name=Mypro
    Exec=/home/softwares/Mypro
    Path=/home/softwares
    Icon=/home/softwares/Myico.png
    Terminal=true
    StartupNotify=false