473,382 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

#! shbang for pyc files?

Is there a way to make it possible to execute a compiled python file
(whatever.pyc) on a linux/unix system without requiring the user to type
"python whatever.pyc"? In the case of a .py file, you can put "#!
/usr/bin/python" at the top and chmod +x, and then you don't even need the
..py extension to run it - just type "whatever" - but when you compile the
file, it loses this ability!

FYI, the context here is that we want to distribute scripts as part of an
application, but we don't want users to go mucking around with the scripts.
Yeah, I know, that's half the fun, but they don't get to muck around with
the C programs, and when they do muck around with the current shell scripts,
it causes us fits because their changes don't get into our source control.

Thanks in advance for any suggestions.
Jul 18 '05 #1
5 1815

"MarkV" <ma********************@yougettheidea.com> schrieb:
.py extension to run it - just type "whatever" - but when you compile the
file, it loses this ability!


Write a wrapper script:

#!/bin/sh
python mycompiledpythonprogram.pyc

Christian
Jul 18 '05 #2
* MarkV (2004-06-05 16:56 +0100)
Is there a way to make it possible to execute a compiled python file
(whatever.pyc) on a linux/unix system without requiring the user to type
"python whatever.pyc"? In the case of a .py file, you can put "#!
/usr/bin/python" at the top and chmod +x, and then you don't even need the
.py extension to run it - just type "whatever" - but when you compile the
file, it loses this ability!


zsh: alias -s pyc=python
Jul 18 '05 #3
On Linux, you can use binfmt_misc to recognize pyc/pyo files by magic
number and execute them directly. This was mentioned in some long-ago
release notes. The magic number is different in newer versios of
Python.

- The interpreter accepts now bytecode files on the command line even
if they do not have a .pyc or .pyo extension. On Linux, after executing

echo ':pyc:M::\x87\xc6\x0d\x0a::/usr/local/bin/python:' > /proc/sys/fs/binfmt_misc/register

any byte code file can be used as an executable (i.e. as an argument
to execve(2)).
[http://mail.python.org/pipermail/pyt...y/012044.html]

Long ago I wrote and submitted a patch to make Python recognize files
with a #! line followed by the magic number, but there seemed to be no
interest.
http://groups.google.com/groups?selm...&output=gplain

Having
#!/usr/bin/env python
import myapp
myapp.main()
really won't spend much time byte-compiling, so normally it's not worth
worrying about.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAweL/Jd01MZaTXX0RAizKAJ9ecPx5o/gYqeE/Lpih0L2yWJe1JACfbm9a
v8vTVfGFIbr/GsXnDY4MK+Y=
=To9F
-----END PGP SIGNATURE-----

Jul 18 '05 #4
On Sat, 5 Jun 2004, Christian Gudrian wrote:

Then why not just use a wrapper Python program
which imports module and runs "main" function?
"MarkV" <ma********************@yougettheidea.com> schrieb:
.py extension to run it - just type "whatever" - but when you compile the
file, it loses this ability!


Write a wrapper script:

#!/bin/sh
python mycompiledpythonprogram.pyc

Christian


Sincerely yours, Roman Suzi
--
rn*@onego.ru =\= My AI powered by GNU/Linux RedHat 7.3

Jul 18 '05 #5
"MarkV" wrote:
FYI, the context here is that we want to distribute scripts as part of an
application, but we don't want users to go mucking around with the scripts.
Yeah, I know, that's half the fun, but they don't get to muck around with
the C programs, and when they do muck around with the current shell scripts,
it causes us fits because their changes don't get into our source control.


here's one way to do it:

http://www.pythonware.com/products/python/squeeze/

</F>


Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
18
by: JKop | last post by:
Here's what I know so far: You have a C++ project. You have source files in it. When you go to compile it, first thing the preprocessor sticks the header files into each source file. So now...
18
by: UJ | last post by:
Folks, We provide custom content for our customers. Currently we put the files on our server and people have a program we provide that will download the files. These files are usually SWF, HTML or...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.