473,598 Members | 3,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Location of bytecode files (pyc)

Rim
Hi,

How can I control the location of the bytecode files?

The reason I ask is I want to place the bytecode in a directory
different than source code for backup reasons. Our backup system is
directory based and I only want to have source code backed up, not
object files or pyc files.

Thanks,
-Rim
Jul 18 '05 #1
8 3107
ri*******@yahoo .com (Rim) writes:
How can I control the location of the bytecode files?


You currently can't. See PEP 304, though, at

http://www.python.org/peps/pep-0304.html

Comments on the PEP are encouraged: If you won't comment now on
whether the proposed change would solve your problem, it might be that
you find something useless got implemented later.

Regards,
Martin
Jul 18 '05 #2

"Rim" <ri*******@yaho o.com> wrote in message
news:6f******** *************** ***@posting.goo gle.com...
Hi,

How can I control the location of the bytecode files?

The reason I ask is I want to place the bytecode in a directory
different than source code for backup reasons. Our backup system is
directory based and I only want to have source code backed up, not
object files or pyc files.
If you're on Windows say:

del /S *.pyc

to remove all .pyc's from cwd and below.

Thanks,
-Rim

Jul 18 '05 #3
On 03 Sep 2003 07:12:07 +0200, ma****@v.loewis .de (Martin v. =?iso-8859-15?q?L=F6wis?=) wrote:
ri*******@yaho o.com (Rim) writes:
How can I control the location of the bytecode files?


You currently can't. See PEP 304, though, at

http://www.python.org/peps/pep-0304.html

Comments on the PEP are encouraged: If you won't comment now on
whether the proposed change would solve your problem, it might be that
you find something useless got implemented later.

Personally, I am a minimalist when it comes to environment variables.
IMO that name space has the same problems as any global namespace,
and since a single default set of user's environment variables tends to
presented to most programs s/he runs from a command window, the name space
usage tends towards a hodgepodge and/or wrapping apps in setup scripts (which
can work fine, but I still don't like it as a standard way to go).

IMO the os.environ name space should be treated like a root directory name space,
and not have application data per se in it (with reluctant exceptions where it is used wholesale
as in CGI). Rather, IMO, and only if necessary in the first place, it should be used to specify
location or search path info for config data, not *be* config data.

And a user-set environment variable should not be able to cause a bypass of root/admin-defined
config info where the distinction is necessary.

(The PYTHONBYTECODEB ASE variable does refer to a directory, but now that makes two variables,
counting PYTHONPATH, and where will it end?)

Provision for admin/root level config data separate from user preference and session state type
config data should be made as necessary and desirable, but secondary/user config data search
should be controllable by the primary/root/admin config data (which e.g. could say to ignore
or use user-controlled/attempted-control environment variables etc.).

This would seem to imply a standard place to look for root/admin level config data, not directed
by env variable. E.g., a read-only file in the same directory as the python interpreter executable,
with, say, .conf or .cfg appended to the name. *That* file can then specify how/whether to look
for user config stuff etc., or specify password access to some features, etc. etc., if we wind up
doing restricted exec stuff.

A user config file overriding any other *user* config info could be specified by command line option,
e.g., -cfg myConfigFile.co nf, and whether this or other command line options were allowed could be
(and should be able to be when control is necessary) specified in the root/admin config file.

.... just my .02USD

Regards,
Bengt Richter
Jul 18 '05 #4
Rim
> If you're on Windows say:

del /S *.pyc

to remove all .pyc's from cwd and below.


Yes, and in linux 'find . -name "*.pyc" -exec rm -rf {} \;', but that
is not the point. I did not ask about how to remove pyc files, I asked
about placing them far from source code, in another directory, so they
would not be seen by the backup software.

The backup software runs continuously day, night, weekends, all the
time. Sweeping the pyc's under the carpet each time the backup is
about to be saving my files is impossible. That is why we store all
gcc object files and executables we produce on non-backed up
filesystems by prefixing target filenames in makefiles with a variable
like $OBJECT_DIR and $EXEC_DIR.

We save hundreds of Gigs of disk space this way.

PEP 304 appears to give me what I need.

As Bengt suggest, adding yet another env var to control the operation
of an application polutes the name space for all applications, but
each app only needs to look at the variables it is concerned with.
PYTHONBYTECODEB ASE is a cleaner approach that has less overhead than a
configuration file. Also, env variables are directly usable in
makefiles, which makes them very attractive and easy to use for
managing where compiler output goes.

Say you work on multiple projects simultaneously with different
locations for the byte code. The configuration files approach becomes
an administrative burden with conditionals based on the project name
in your config file.

The typical way we handle project specific configurations is through
environment variables that get set in the startup files. Depending on
a PROJECT environment variable, the PYTHONBYTECODEB ASE can easily be
set to different directories without creating additional .cfg files.

Regards,
-Rim
Jul 18 '05 #5
Rim wrote:
If you're on Windows say:

del /S *.pyc

to remove all .pyc's from cwd and below.


Yes, and in linux 'find . -name "*.pyc" -exec rm -rf {} \;', but that
is not the point. I did not ask about how to remove pyc files, I asked
about placing them far from source code, in another directory, so they
would not be seen by the backup software.

The backup software runs continuously day, night, weekends, all the
time. Sweeping the pyc's under the carpet each time the backup is
about to be saving my files is impossible. That is why we store all
gcc object files and executables we produce on non-backed up
filesystems by prefixing target filenames in makefiles with a variable
like $OBJECT_DIR and $EXEC_DIR.


You have a fancy backup system like this, involving hundreds of Gigs,
and it can't apply a simple filter to avoid .pyc and .obj files?!

-Peter
Jul 18 '05 #6

Bengt,

Thanks for your feedback...

MvL> http://www.python.org/peps/pep-0304.html

MvL> Comments on the PEP are encouraged: ...

Bengt> Personally, I am a minimalist when it comes to environment
Bengt> variables. IMO that name space has the same problems as any
Bengt> global namespace, and since a single default set of user's
Bengt> environment variables tends to presented to most programs s/he
Bengt> runs from a command window, the name space usage tends towards a
Bengt> hodgepodge and/or wrapping apps in setup scripts (which can work
Bengt> fine, but I still don't like it as a standard way to go).

You can set sys.bytecodebas e explicitly, though you might have trouble
setting it early enough to push all your .pyc files where you want. Note
that the patch associated with PEP 304 is written in C (import.c and
sysmodule.c are affected).

Bengt> Provision for admin/root level config data separate from user
Bengt> preference and session state type config data should be made as
Bengt> necessary and desirable, but secondary/user config data search
Bengt> should be controllable by the primary/root/admin config data
Bengt> (which e.g. could say to ignore or use
Bengt> user-controlled/attempted-control environment variables etc.).

Do you want Python to locate and load a config file at startup? By the time
a config file parser is loaded and sys.bytecodebas e set, lots of .pycs may
well have already been generated in the wrong place. This shouldn't happen
with the patch I created.

Bengt> This would seem to imply a standard place to look for root/admin
Bengt> level config data, not directed by env variable. E.g., a
Bengt> read-only file in the same directory as the python interpreter
Bengt> executable, with, say, .conf or .cfg appended to the name. *That*
Bengt> file can then specify how/whether to look for user config stuff
Bengt> etc., or specify password access to some features, etc. etc., if
Bengt> we wind up doing restricted exec stuff.

Like I said, lots of other stuff will likely have been imported by the time
you realize your .pyc files belong "over there" instead of where they're
being written, or were you volunteering to write a C version of ConfigParser
which is statically linked into the interpreter? ;-)

Skip

Jul 18 '05 #7

Rim> As Bengt suggest, adding yet another env var to control the
Rim> operation of an application polutes the name space for all
Rim> applications, but each app only needs to look at the variables it
Rim> is concerned with. PYTHONBYTECODEB ASE is a cleaner approach that
Rim> has less overhead than a configuration file. Also, env variables
Rim> are directly usable in makefiles, which makes them very attractive
Rim> and easy to use for managing where compiler output goes.

You can also set sys.bytecodebas e in your application code instead of
relying on PYTHONBYTECODEB ASE. That may not be helpful when doing a big pyc
compile, as when running compileall.py. In that case, you can simply set
PYTHONBYTECODE base for that specific command. Still, in your environment,
it sounds like you'd want to set it in the /etc/profile (or similar). It
could still be set to a user-specific directory, just one that's on a
filesystem which is not backed up.

The intention was that the most common usage would be for a person to
execute something like

PYTHONBYTECODEB ASE=/tmp/$USER/python ; export PYTHONBYTECODEB ASE

in their .profile (or equivalent for non-sh-style shells or platforms).
Clearly, other usage is possible however.

Skip

Jul 18 '05 #8
Rim
> The intention was that the most common usage would be for a person to
execute something like

PYTHONBYTECODEB ASE=/tmp/$USER/python ; export PYTHONBYTECODEB ASE


This is exactly how I intent to use it.

Regards,
-Rim
Jul 18 '05 #9

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

Similar topics

46
6244
by: Jon Perez | last post by:
Can one run a 1.5 .pyc file with the 2.x version interpreters and vice versa? How about running a 2.x .pyc using a 2.y interpreter?
5
2264
by: LutherRevisited | last post by:
This may be a dumb question, but are there any practical advantages of compiling a python application to *.pyo, or *.pyc? I haven't noticed any difference in the performance of text *.py or a bytecompiled file.
1
3105
by: Bo Jacobsen | last post by:
I have a number of files compiled to bytecode using py_compile.compile(). The .pyc files can be invoked by python directly ($python file.pyc), but "loading" them by execfile just throws an exception ? Any suggestions Bo.
33
1997
by: Maurice LING | last post by:
Hi, I've been using Python for about 2 years now, for my honours project and now my postgrad project. I must say that I am loving it more and more now. From my knowledge, Python bytecodes are not back-compatible. I must say that my technical background isn't strong enough but is there any good reason for not being back-compatible in bytecodes? My problem is not about pure python modules or libraries but the problem is with 3rd party...
0
1198
by: sxanth | last post by:
>What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't >reachable? Does the compiler just throw in a default 'return None' >epilogue, with routes there from every code path, even when it's not >needed? If so, why? Hi. pyc (http://freshmeat.net/projects/pyc) can already remove that unused code since June.
4
3292
by: kwatch | last post by:
Hi, It is possible to get bytecode from code object. Reversely, is it possible to create code object from bytecode? ex. ## python code (not a module) pycode = '''\ print "<ul>\n" for item in items:
2
2168
by: warhero | last post by:
First question, I can't seem to get any python bytecode to be produced. I've tried different techniques from chapter 30.8 to chapter 31 of the python guide.. I was under the assumption that after compiling a file, it would output a pyc file, but where does it go? Any help would be appreciated. Second, Are there any other projects out for bundling python bytecode files, making it able to use a couple files to distribute an entire app?? ...
0
7991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7902
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8395
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
8265
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
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2412
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
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.