How to create a Linux executable file using python code
Basically, to make a file executable in Unix systems, you just have to do one thing: allow it to be executed (very surprising ;) ). To do it, you must use the chmod
command as follows: chmod +x youfile.py
. The +x
add the right to be executed.
Now, your system will allow you to execute the script, but for now it's just a simple text file... Ubuntu doesn't know that he must use the python
command to run it, so you'll have undermined comportment. To resolve this, we use the sha-bang line (for more information, see the wikipedia page): at the first line of your script, you must write #! program_to_use
, in your case it's python. Generally, we take benefit of the env
variables, and use #! /usr/bin/env python
, but you can also choose yourself the version of python you want, doing #! /usr/bin/pythonX.X
where X.X is the version of python.
How to create an executable for a shell script in Ubuntu?
An executable in linux is a file with the executable bit on. Thus you simply modify it with chmod
:
chmod +x decBright.sh
Then you can run it with:
./decbright.sh
You can also run it by double-clicking in many graphical linux distributions.
You also better provide a "Shebang": the first line of your script should specify the "interpreter":
#!/bin/bash
Or any other interpreter (at the first line of your file).
How to compile for Windows on Linux with gcc/g++?
mingw32 exists as a package for Linux. You can cross-compile and -link Windows applications with it. There's a tutorial here at the Code::Blocks forum. Mind that the command changes to x86_64-w64-mingw32-gcc-win32
, for example.
Ubuntu, for example, has MinGW in its repositories:
$ apt-cache search mingw
[...]
g++-mingw-w64 - GNU C++ compiler for MinGW-w64
gcc-mingw-w64 - GNU C compiler for MinGW-w64
mingw-w64 - Development environment targeting 32- and 64-bit Windows
[...]
Related Topics
Running 32 Bit Assembly Code on a 64 Bit Linux & 64 Bit Processor:Explain the Anomaly
How to Monitor the Thread Count of a Process on Linux
Colour Highlighting Output Based on Regex in Shell
Bash: Silently Kill Background Function Process
Syntax Error Near Unexpected Token 'Then'
Assembly: Printf Not Printing New Line
Display Two Files Side by Side
How to Get the Difference (Only Additions) Between Two Files in Linux
Bash Read/Write File Descriptors -- Seek to Start of File
Faster Forking of Large Processes on Linux
Extract Lines Between Two Patterns from a File
How to Run Crontab Job Every Week on Sunday
Run Script with Rc.Local: Script Works, But Not at Boot
Why Exit Code 141 with Grep -Q
Write a Bash Shell Script That Consumes a Constant Amount of Ram for a User Defined Time