I have a shell script file ‘program’:
it is an executable (I made it an executable from the properties) and I can run it from a console with ‘./program’. But when I double-click on the file nothing happens. I thought that was the whole point making it executable. Otherwise I can type the command itself in a console. Does anyone know how to make it run by clicking the mouse rather than from a console? Thank you.
Try using the full path to ‘main.pyw.’ The ‘./’ will make Python look in the current active directory.
The shell script is in the same folder as the python script. But if I use a full path it won’t be cross-platform/portable anymore.
Try the full path, just to see if that’s causing the problem.
The directory where the shell script resides and the current directory at execution time are different things. There are codes you can use in shell scripts to find the directory where it lives and then you can chdir there or to prepend that directory to any filenames.
Guys, thank you but I would like a solution not a theory on how it’s possible to do things.
- I don’t want to include full path if it’s possible
- The shell script will either be in the same folder as the python script or the Python script will at least be in a relative folder
- I don’t want to write a whole program in another script. What’s the point writing a script for a script? I just want to run my Python script by clicking a mouse. Otherwise the user can always run it directly from a console.
- There’s a Py-exe or something like this in windows to make an executable out of a script. Is there anything like this in Linux?
Is that possible? Or the only option is what you have already told me - to write a bigger shell script with folder searches and everything? If you have an example, I’d appreciate it, it’ll save me a lot of time. Thank you.
Is your python app gui or console?
See how you go if you create a desktop application link…
Right-click on the desktop -> Create New -> link to application.
Fill in the details.
If you need it to run in a terminal, click Advanced Options on the Application tab. Select Run in terminal.
You look at $0 of the script. That will either be the full path or a relative path. That will give you the directory the script lives in. By your convention, that will also be where the Python program is.
I do not really understand why you write a bash script to start a python
script. It is much more easier to run a python script by making it
executable the proper way
# -*- coding: utf-8 -*-
from PyQt4 import Qt
a = Qt.QApplication(sys.argv)
hello = Qt.QLabel("Hello, World")
put this into hello.py
chmod +x hello.py
and automagically you can start it by clicking from dolphin (or nautilus)
Martin Helm wrote:
> and automagically you can start it by clicking from dolphin (or nautilus)
forgot to add the link
That worked like a charm! That’s exactly what I was looking for. Thank you very much.
I wrote a(nother) wrapper for ffmpeg in C# for Mono on Linux and learnt that many don’t like running Mono on Linux. That’s fine. So I ported my whole app from C# to Python. And learnt Python on the way - it’s such a great language, I’m hooked now.
If you would like to have a look at my video/audio/image codec app, please visit the SourceForge site: Cute Giraffe | Get Cute Giraffe at SourceForge.net and download the PyQt version. But bear in mind it’s only the beginning of development and it has just the basic functionality which I plan to extend in the near future.
Ah, just wait till you see the other languages on offer in the Language Candy Store.