By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,919 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,919 IT Pros & Developers. It's quick & easy.

pyc files located elsewhere?

P: n/a
Greetings.

On Python 2.3.3, is there any way to have the .pyc files created
elsewhere than in the same dir as the source files?

I have an application that consists of about 30 source files including
a few packages.

I would like it if my .pyc files could be in a subdir of the app root
if possible. I would have to make sure that the subdir structure
underneath matched the structure of the app itself.

I would also consider having each package directory have its own PYC
directory and the compiled files could go in there even.

So, can I feed a prefix to the system that checks for and creates .pyc
files somehow? My review of the Pydocs for related compilation issues
didn't seem to turn up an answer.

Thanks.
--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
> I would like it if my .pyc files could be in a subdir of the app root
if possible. I would have to make sure that the subdir structure
underneath matched the structure of the app itself.

I would also consider having each package directory have its own PYC
directory and the compiled files could go in there even.

So, can I feed a prefix to the system that checks for and creates .pyc
files somehow? My review of the Pydocs for related compilation issues
didn't seem to turn up an answer.


I don't know if it is possible to automatically write to a different
path, but I /think/ one can /turn off/ writing .pyc files, but it would
necessarily make running the script slower (you don't get cached .pyc
files, so every import requires a py->ptc compilation).

- Josiah

Jul 18 '05 #2

P: n/a
Josiah Carlson wrote:
I don't know if it is possible to automatically write to a different
path, but I /think/ one can /turn off/ writing .pyc files, but it would
necessarily make running the script slower (you don't get cached .pyc
files, so every import requires a py->ptc compilation).


Just to clarify (and I don't know turning that feature off is really
possible, so maybe it's a useless point), but not *every* import will
require the compilation. The first import of any given module will
require the compilation, each time you run the application. If a
module is imported fifty times, all but the first just retrieve
the module from sys.modules, same as normal.

(Is what you describe really possible? I've never heard of it.)

-Peter
Jul 18 '05 #3

P: n/a
>
(Is what you describe really possible? I've never heard of it.)


It seems that its at least not doable using commandline args. But I have to
admit that I love to see that feature - so far, pyc didn't by me anything
except trouble to clear my src-dirs when using a version control system to
prevent them beeing checked in. I'm very well aware of .cvsignore and the
like - but I'd prefer to turn off the compilation.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #4

P: n/a
> Josiah Carlson wrote:
I don't know if it is possible to automatically write to a different
path, but I /think/ one can /turn off/ writing .pyc files, but it would
necessarily make running the script slower (you don't get cached .pyc
files, so every import requires a py->pyc compilation).
Just to clarify (and I don't know turning that feature off is really
possible, so maybe it's a useless point), but not *every* import will
require the compilation. The first import of any given module will
require the compilation, each time you run the application. If a
module is imported fifty times, all but the first just retrieve
the module from sys.modules, same as normal.


Right, but if you have 50 modules that are imported (50 unique module
files), then you still have to compile those 50 every time. The speed
hit really depends on the size of the application, and how often
restarts occur.

(Is what you describe really possible? I've never heard of it.)


I know that importing from a non-writable location disables writing of
pyc files (zip imports, etc.), and I am fairly certain it can be done
with an import hook, though never having need for it, I've never tried.

- Josiah

Jul 18 '05 #5

P: n/a
(Is what you describe really possible? I've never heard of it.)


Josiah> I know that importing from a non-writable location disables
Josiah> writing of pyc files (zip imports, etc.), and I am fairly
Josiah> certain it can be done with an import hook, though never having
Josiah> need for it, I've never tried.

Please have a look at PEP 304. Feedback welcome.

Skip
Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.