473,657 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2309
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
"$PYTHONPAT H" 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.pytho n:
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.m ain()

-- =============== =============== =============== =============== == <
wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.ne tcom.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*****@python ware.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

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

Similar topics

5
9197
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
4478
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 that shebangs were only appropriate for Python code intended to be executable (i.e., run from the command line).
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.