You are not logged in.
Pages: 1
Hello fellow arch users,
I would like to know what is the standard way of distributing a python programm (single file script). I tried to use distutils, and I managed to create a windows executable but failed at creating a linux binary file. I tried
python3 setup.py bdist
but all I get is a tar.gz file with no executable inside. Do I just create a deb or an rpm or a pkg to manage dependencies?
Thank you all in advance.
Last edited by baion baion (2010-07-19 16:15:42)
Offline
I'm sorry, I can't be of any help, but I was wondering the same thing.
I suppose I would just put the Python file in a directory, add a SH script that has the same name but without the ".py", make it executable, and have it run the program.
As you found out, it doesn't seem to be too hard to make a Windows executable from a Python file.
Offline
But what if I want to create a linux executable without releasing the source? I am not planning to do so as I support the open source movement but I would like to know.
And how can I "install" a python program in linux. Do i just copy the .py file in /usr/bin?
Offline
As far as I know, it's not possible to distribute a Python program without also releasing the source. At least, not easily. I hope someone with more Python experience will correct me if I'm wrong.
As for installation, I believe the standard is to put all of your files in "/usr/share/" and to put an executable SH script to start it in "/usr/bin/".
/usr/bin/MyApplication
/usr/share/MyApplication/MyApplication.py
Offline
I don't know that much about this, but what about .pyc files? And why have a shell script to execute a python script instead of a shebang?
Offline
And why have a shell script to execute a python script instead of a shebang?
So my application doesn't have a silly ".py" extension.
...but, technically, there's no reason to not use a shebang.
Offline
I don't know that much about this, but what about .pyc files? And why have a shell script to execute a python script instead of a shebang?
I would use the shebang approach as well.
As far as I know, there is no good way to make native executables out of Python code, bar packaging a copy of the source with a statically linked Python executable. .pyc files require the Python program to run, but technically you could distribute them as a complete system, I think. (It would be akin to distributing Java .class files.)
Offline
I've never made a binary distributable from a python script. Maybe I should be using setuptools or distutils or something, but here's what I do in my python program's pkgbuild:
build() {
cd $srcdir/$pkgname-$pkgver
install -Dm755 chipmunk-radio.sh ${pkgdir}/usr/bin/$pkgname || return 1
install -Dm755 chipmunk-radio.py ${pkgdir}/usr/share/$pkgname/$pkgname.py || return 1
install -Dm755 chipmunk-radio.glade ${pkgdir}/usr/share/$pkgname/$pkgname.glade || return 1
install -Dm755 chipmunk-radio.desktop ${pkgdir}/usr/share/applications/$pkgname.desktop || return 1
install -Dm755 chipmunk-radio.png ${pkgdir}/usr/share/icons/hicolor/128x128/apps/$pkgname.png || return 1
}
Offline
Can you please explain what that build command does? I am not that familliar with pkgbuilds.
@dcrouzelis: So if I have a single file command line apllication, by placing it inside /usr/bin will I be able to run it from a terminal without navigating to the directory where the source file is? And will I have to invoke python3 application.py or just apllication.py? I don't have a linux machine at the moment to check for myself.
Last edited by baion baion (2010-07-19 22:45:45)
Offline
But what if I want to create a linux executable without releasing the source?
You only need to distribute the .pyc files instead of the .py files. However, this will only make it harder. Python is an interperted language so the .pyc files can be turned back into understandable .py files. Similar to decompiling Java .class files.
And how can I "install" a python program in linux. Do i just copy the .py file in /usr/bin?
No. You will put a wrapper script in /usr/bin that will invoke the main script file. Your best bet it to learn distutils for creating install scripts. Take a look at Niw Markdown Editor (a project of mine). It has a simple distutils install setup. For a much more complicated example that has a multi-platform build system (and includes building C based modules) look at calibre.
Offline
> You only need to distribute the .pyc files instead of the .py files.
+1
Does http://www.py2exe.org/ work? Maybe you can run the app through wine ;-P
Last edited by karol (2010-07-20 06:44:57)
Offline
I found something!
It is called cx_freeze and it works with both python 2.7 and python 3.1.1, at least on windows. I will test it on Arch tomorrow and see, although I guess I could just use the .py files and call them with a bash script as dcrouzelis has suggested.
Offline
Can you please explain what that build command does? I am not that familliar with pkgbuilds.
The source consists of 5 files, and the build command copies each one to a matching directory:
chipmunk-radio.sh
simple launcher script, /usr/bin/chipmunk-radio
chipmunk-radio.py
the program, /usr/share/chipmunk-radio/chipmunk-radio.py
chipmunk-radio.glade
the gui definition, /usr/share/chipmunk-radio/chipmunk-radio.glade
chipmunk-radio.desktop
the launcher item for system menus, /usr/share/applications/chipmunk-radio.desktop
chipmunk-radio.png
the fallback application icon, /usr/share/icons/hicolor/128x128/apps/chipmunk-radio.png
Offline
Thank you for your answer. Well if all you want to do is copy the files, then why use the build command? Why not just use the cp command? I assume that the Dm755 parameter has sets the files' access permission?
Last edited by baion baion (2010-07-21 21:38:39)
Offline
So my application doesn't have a silly ".py" extension.
The hashbang has higher precedence than the extension, you don't need the .py.
I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.
Offline
There is one Python-specific exception: If you want to import your Python file as a module from another Python file, it needs to end in .py and be in the Python path. However, for a top-level script, I would probably call this a Bad Idea. For executable scripts, ditch the extension and call it what you want.
Offline
Pages: 1