Python GUI for my shell scripting - python

I have written some simple Linux shell script. Now I am trying to figure out is that can I have a GUI developed with python and trigger my shell scripts from the GUI.
Is this possible. How can I do this. Any ideas or examples please.
Thanks.

Just make sure the python executable is in your PATH environment variable then add in your script
python path/to/the/python_script.py
Details:
In the file job.sh, put this
!/bin/sh
python python_script.py
Execute this command to make the script runnable for you : chmod u+x job.sh
Run it : ./job.sh

Related

Add Python terminal in VS Code

I am trying to run Python from VS Code. I have already activated python through the terminal. However, in the terminal selector in the lower right of the screen, I cannot find Python terminal option there:
I wish to ask how could I make Python terminal visible here so that the next time I wish to switch terminal to Python, I do not have to load a .py file but could just selecting Python terminal directly. Thank you.
Python terminals aren't really a thing. If you want to run a .py file, do $ python [filename].py or $ python3 [filename].py. If you want to just run commands, open a Python shell by doing $ python or $ python3
There is no Python terminal. If you are asking about loading Python shell you just have to type python into your terminal to load the Python shell

Calling a python file of virtual environment from applescript

I have got an applescript and a python script.
The applescript should be the frame of the python script and should execute the python script.
The python script uses a python version and packages, that are saved in a virtual environment.
How can I make the applescript run the python script inside of the virtual environment, so that all the packages and python versions of this environment are used?
My way to do this without applescript was to type source virtualenvironment/bin/activate and after that python /Users/abc/script.py into the terminal.
Using the applescript command
do shell script "source virtualenvironment/bin/activate"
do shell script "python /Users/abc/script.py"
does not work for me. Thanks in advance for your help !
You don't have to activate a virtualenv; that mostly just sets your PATH environment variable so that when your shell looks up what executable to use for the python command, it finds virtualenvironment/bin/python before any other python executables. Just use the expanded, full path, so /virtualenvironment/bin/python instead of python:
do shell script "v/irtualenvironment/bin/python /Users/abc/script.py"
You can also make /Users/abc/script.py executable by making the first line a shebang pointing to your virtualenv Python executable:
#!/virtualenvironment/bin/python
and setting the executable flag on the file (chmod +x script.py, from a terminal).

How to run python script in directory in Cron (Raspberry Pi)

I just started using Cron to automate this one python script I have. I understand how to use all the time parameters in nano, but I'm confused with how you would run the script. Normally just to run it right from the console, I would do:
cd /pi/home/weather/Adafruit_Python_BMP/examples
and then from there I would run the script with:
python weatherFINAL.py
Now that I'm trying to automate this in Cron, I can't do the multiple commands to cd into the directory, and then run the program. I know this is probably a really easy problem to fix, but I've been stuck on this for a while. Any help is appreciated
It is quite simple:
Write a shebang line on the top of your script in order to make it executable:
!/usr/bin/env python
Make sure you can execute that script with chmod command:
$ chmod +x
Programn a crontab task with contrab command:
$contrab -e

Running python3 programs on osx Lion

I can use python 3 in terminal fine, but I don't know how to make it so terminal will run a program that I have written in python 3.
What do i have to do to associate the .py file extension with python3.2.3 for terminal and not python2.7.1
I am using textwrangler as my text editor, but will happily use any editor if it will run, though I don't think this is my problem as idle doesn't work either and it doesn't have line numbers in it either.
Kind regards
Rob
Add a python3 hashbang to the beginning of your scripts:
#!/usr/bin/env python3
# do stuff
Then, you can make your script executable and run it:
chmod +x script.py
./script.py
try python3 yourprogram.py in your terminal.
or by adding this line on the top of our programs, this is the path to your interpreter:
#!/usr/local/bin/python3.2

How do I get linux to automatically run my python script in the Python interpreter?

I've decided that it would be good for me to move outside of my .NET bubble and start experimenting with other technologies. I have Ubuntu12 running and python2.7 and 3.2 are installed. I can run code directly in the interpreters.
I have a basic script on the filesystem called Standalone.py:
#!/usr/bin/env python3.2
import sys
print("this is a standalone script.")
When I'm at my bash prompt I type $ python3.2 Standalone.py. I get a response saying this is a standalone script. But when I type $ Standalone.py then it tells me that the command is not found.
How do I run such scripts?
Thanks for any help.
update
I changed the permissions of Standalone.py to 755. Then I ran the command:
$ ./Standalone.py
and received the message:
: No such file or directory
I then switched the permissions of Standalone.py back to 644. Then when I ran
$ ./Standalone.py
I received the message
-bash: ./Standalone.py: Permission denied
Is there something I'm missing?
You need to make the script executable using
chmod +x Standalone.py
Usually, the current directory is not searched for executable files, so you need to use
./Standalone.py
to tell the shell that the script is in the current directory.
Make sure your script file has linux newline (just \n) not windows newline (\r\n). Did you write the script on windows? This happened to me once. You should check your editor settings.
Your script should start with #!/usr/bin/python not #!/usr/bin/env python3.2
Make sure you're in the folder where your script is located you can check with ls
chmod +x Standalone.py
./Standalone.py
At first, to excecute a script it need to be executable. So you either have to do a chmod +x $file or a chmod 0740 $file. When you set the file permission to 644 you are putting the execute right away, so if gives you an error. If you are unsure of execution right and octal notation, you can use this : http://permissions-calculator.org/decode/0644/.
To really answer your question then, if you want to call the script with $file.py it needs to be in your PATH variable. You can display it with echo $PATH. Those are the directories that are searched for script to execute. So you simply need to give your script the executable right and put it in one of the directory given by your PATH.
Can you check if /usr/bin/python or /usr/bin/python3.2 exists
Execute below comamnd:
which python3.2
and then use the resulting path on top of you script.

Categories