473,386 Members | 1,785 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,386 software developers and data experts.

compile shebang into pyc file

Hello,

is there a way to compile a python file foo.py to foo.pyc (or foo.pyo)
such that foo.pyc can be run with 'foo.pyc' (as opposed to 'python
foo.pyc') on the command line?

Jörg Schuster

Jul 19 '05 #1
11 2294
Is there some reason why you want to run the .pyc file, rather than the
..py file? If you start the script with

#! /usr/bin/env python

Then if the file has the execution permission set, typing the file name
(foo.py) will make the script call up the Python interpreter on its
own.

Jul 19 '05 #2
On 26 Apr 2005 18:15:51 -0700, jo**************@gmail.com
<jo**************@gmail.com> wrote:
Is there some reason why you want to run the .pyc file, rather than the
.py file? If you start the script with


a. It's more efficient, since the code doesn't need to be compiled
before it's run.
b. What if you want to ship closed-source?

Mike

--
Michael P. Soulier <ms******@gmail.com>
http://www.digitaltorque.ca
http://opag.ca python -c 'import this'
Jul 19 '05 #3
Michael Soulier wrote:
Is there some reason why you want to run the .pyc file, rather than the
.py file? If you start the script with


a. It's more efficient, since the code doesn't need to be compiled
before it's run.
b. What if you want to ship closed-source?


#!/usr/bin/env python
import app

hardly qualifies as "hard to compile" or "open source"

</F>

Jul 19 '05 #4
> #!/usr/bin/env python
import app


Yes, of course this is a possibility. But it implies having (or giving
away) two files.

I think having one file is always better than having two files. Because
if you have two files, you need a third one: a README that tells you
what to do with the two files and that one of the files must either be
in $PYTHONPATH, or in the same directory as the other one and '.' must
be in your $PYTHONPATH , and so on. Actually, some people will also
need a fourth file: One that contains an explanation of terms like
"$PYTHONPATH" and the like.

Jörg

Jul 19 '05 #5
I just happened across the page linked to below, and remembered this
thread, and, well... here you go:

http://www.lyra.org/greg/python/

Executable .pyc files

Ever wanted to drop a .pyc file right into your web server's
cgi-bin directory? Frustrated because the OS doesn't know what to do
with a .pyc? (missing the #! line)

Look no further! :-) Below is a tiny Bash script to do this. "cat"
your .pyc onto the end of this and drop it wherever you need direct
execution of that .pyc

Jul 19 '05 #6
On Wed, 27 Apr 2005 10:37:11 -0400, Michael Soulier <ms******@gmail.com>
declaimed the following in comp.lang.python:
a. It's more efficient, since the code doesn't need to be compiled
before it's run.
b. What if you want to ship closed-source?
You stuff the real code into a module that gets imported (hence
cached as a .pyc), and the main program in source looks like:

import thedirtystuff
thedirtystuff.main()

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 19 '05 #7
Joerg Schuster wrote:
#!/usr/bin/env python
import app
Yes, of course this is a possibility. But it implies having (or giving
away) two files.


yeah, think of all the disk space you'll waste!
Because if you have two files, you need a third one: a README
that tells you what to do with the two files
so you're saying that the set of people that can deal with no more than one
file at a time but knows how to install and configure Python (which in itself
comes with a few thousand files) is larger than zero?
I think having one file is always better than having two files.


so you don't ever use modules?

you haven't distributed many Python programs, have you?

</F>

Jul 19 '05 #8
On 2005-04-27, Fredrik Lundh <fr*****@pythonware.com> wrote:
so you're saying that the set of people that can deal with no
more than one file at a time but knows how to install and
configure Python (which in itself comes with a few thousand
files) is larger than zero?


There are a lot of Linux users who already have python
installed but don't know it. Python was always a required package for
a RedHat install. It's not required on some distros, but it's
installed by default and you've got to go out of your way to
de-selected it when you install.

I've found that giving Linux users a single file "executable"
Python script works wonderfully, but it's really only an option
for fairly small applications -- and I don't care if they have
source code.

--
Grant Edwards grante Yow! Look!! Karl Malden!
at
visi.com
Jul 19 '05 #9
rbt
Fredrik Lundh wrote:
Joerg Schuster wrote:
> #!/usr/bin/env python
> import app


Yes, of course this is a possibility. But it implies having (or giving
away) two files.

yeah, think of all the disk space you'll waste!
Because if you have two files, you need a third one: a README
that tells you what to do with the two files

so you're saying that the set of people that can deal with no more than one
file at a time but knows how to install and configure Python (which in
itself
comes with a few thousand files) is larger than zero?


On Windows, installing Python takes only a few clicks. No brain cycles
needed ;)
Jul 19 '05 #10
On Wed, 27 Apr 2005 16:48:35 -0400, rbt <rb*@athop1.ath.vt.edu>
declaimed the following in comp.lang.python:

On Windows, installing Python takes only a few clicks. No brain cycles
needed ;)
Until you try to set it so that ActiveState Python(win) doesn't
conflict with Plone-2 Python (at least I'm still on 2.3.x -- If it
worked, I removed ASP, installed P2, then told ASP to install into the
P2 Python directory...)

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 19 '05 #11
> so you're saying that the set of people that can deal with
no more than one
file at a time but knows how to install and configure Python
(which in itself
comes with a few thousand files) is larger than zero?


Take me as an example: Very often, I needed software that could solve a
specific problem. I used to find, say, 10 different packages. Usually
none of the programs REALLY did the job as I wanted it to be done. Yet,
in order to find this out (or in order to find the package that suited
my needs best), I had to try out all of these packages. This used to
take an unnecessary amount of time.

I would have found (say) one java program, one c++ program, one Python
program, one perl program, ...

I know that java, c++, Python and Perl are all installed on our system.
And if they weren't, I would know how to install them myself: By using
yast or by saying 'apt-get install <package>'.

Yet: I don't want to have to know how to install all these packages in
all these different languages. I think a program should work out of the
box. And the should be no fumbling it out of the box.

Jörg

Jul 19 '05 #12

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

Similar topics

5
by: deko | last post by:
In regard to running php scripts with cron - Here is a sample script: <?php //debug.php echo "<br> This is a test"; ?> I can call debug.php from a web page on my site like this:
13
by: Chris Lasher | last post by:
Should a Python module not intended to be executed have shebang/ hashbang (e.g., "#!/usr/bin/env python") or not? I'm used to having a shebang in every .py file but I recently heard someone argue...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.