2

I have written a python program and cx_freeze it so that it can be moved to other Linux machine to execute, everything went fine, except the following

After freezing all my python code, I then dpkg build it and marked /usr/bin/myProgram as my installation directory, everything went fine, I can build and install the program to the designated directory but I can only change the directory and ./myProgram to start my program, if I do not do so, I will be told the error of missing my settings.xml which is an external file sitting beside my main program which also resides in /usr/bin/myProgram.

I want to make a desktop shortcut, and I assume full path is needed to execute the program without changing the directory to my program's directory first, is there anything I can do to make this happen?

Message shows that I am missing a setting.xml file when I use full path to run the program, but when I first change to that directory and ./myProgram, it works fine

enter image description here

Thanks very much for the help.

Jahid
  • 21,542
  • 10
  • 90
  • 108
user2499325
  • 419
  • 1
  • 5
  • 15
  • Also you can detect proper location of your executable which is independent of where and how it was ran from. Then you can append your file location to the executable directory path. So you do not load your file as `settings.xml` but `os.path.join(application_root_dir, "settings.xml")`. – Fenikso May 13 '15 at 13:01
  • See http://stackoverflow.com/questions/10293808/how-to-get-the-path-of-the-executing-frozen-script/10294435#10294435 . – Fenikso May 13 '15 at 13:02

1 Answers1

2

A workaround would be to create a simple script to cd to the directory and run the executable with ./myProgram, and then call that script with full path with desktop launcher.

Another way: There's a Path key available in desktop launcher. You can set it like:

Path=working_directory_path

in the .desktop file

Jahid
  • 21,542
  • 10
  • 90
  • 108
  • Thanks for the suggestion, indeed I have already used this method, but I assume we should have a better solution? – user2499325 May 12 '15 at 08:35
  • @user2499325 You can set working directory in .desktop file with `Path` – Jahid May 12 '15 at 08:50
  • Thanks for the Path attribute, I got it done now!! I am just thinking that maybe there are something I can do in the cx_freeze process, maybe I do something wrong there... – user2499325 May 12 '15 at 09:28