Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > compile shebang into pyc file

Reply
Thread Tools

compile shebang into pyc file

 
 
Joerg Schuster
Guest
Posts: n/a
 
      04-26-2005
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

 
Reply With Quote
 
 
 
 
johnlichtenstein@gmail.com
Guest
Posts: n/a
 
      04-27-2005
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.

 
Reply With Quote
 
 
 
 
Michael Soulier
Guest
Posts: n/a
 
      04-27-2005
On 26 Apr 2005 18:15:51 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed)
<(E-Mail Removed)> 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 <(E-Mail Removed)>
http://www.digitaltorque.ca
http://opag.ca python -c 'import this'
 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      04-27-2005
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>

 
Reply With Quote
 
Joerg Schuster
Guest
Posts: n/a
 
      04-27-2005
> #!/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

 
Reply With Quote
 
Steve M
Guest
Posts: n/a
 
      04-27-2005
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

 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      04-27-2005
On Wed, 27 Apr 2005 10:37:11 -0400, Michael Soulier <(E-Mail Removed)>
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()

--
> ================================================== ============ <
> (E-Mail Removed) | Wulfraed Dennis Lee Bieber KD6MOG <
> (E-Mail Removed) | Bestiaria Support Staff <
> ================================================== ============ <
> Home Page: <http://www.dm.net/~wulfraed/> <
> Overflow Page: <http://wlfraed.home.netcom.com/> <

 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      04-27-2005
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>

 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      04-27-2005
On 2005-04-27, Fredrik Lundh <(E-Mail Removed)> 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
 
Reply With Quote
 
rbt
Guest
Posts: n/a
 
      04-27-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable use of pyc file with no matching py file Roy Smith Python 19 02-12-2012 06:53 PM
howto compile recursively all *.py files to *.pyc (from a directory my_dir)? dmitrey Python 1 09-02-2007 09:27 AM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM
Cross compile generation of .pyc from .py files... venkatbo@yahoo.com Python 7 03-01-2006 09:00 PM
Compile C program -> .pyc file Ernesto Python 5 10-21-2005 03:52 PM



Advertisments