Any way to not create .pyc files?
Mark Tolonen
nospam at nospam.com
Thu Jun 9 16:57:07 EDT 2005
"Lonnie Princehouse" <finite.automaton at gmail.com> wrote in message
news:1118337243.321804.284910 at g14g2000cwa.googlegroups.com...
> In short:
>
> Is there any way to run Python WITHOUT trying to create .pyc files (or
> .pyo) or to have Python not attempt to import the .pyc files it finds?
>
> Reason:
>
> We have a site-specific package installed on a network drive[1]. When
> anyone with write access imports this package, the network drive gets
> spammed with .pyc files.
>
> If these .pyc files exist, they appear to cause problems when other
> users' Python interpreters use them instead of the .py files. (I know,
> they *should* work, but they don't). This may have something to do
> with the fact that all of these users (on Windows) have the network
> drive mapped to arbitrary drive letters. I don't know.
>
> PEP 304 would have helped, but it appears to be deceased. What I
> really want is a command line option
>
> I'm going to have to cobble together a work-around, like having
> imported modules delete their own .pyc files immediately after import,
> but it would be really nice to have a /good/ way of not using .pyc...
>
> (footnotes)
>
> [1] Because it's an administrative nightmare to distribute code updates
> to dozens of non-technical users
>
Are you using ActivePython? ActivePython's installation updates the PATHEXT
environment variable on Windows with the .pyc and .py extensions (.pyc
first). This environment variable is used to try extensions when you run a
program from the command line without an extension.
Example:
[1] C:\ex>set pathext
PATHEXT=.com;.exe;.bat;.cmd;.pyc;.py
[2] C:\ex>echo print "old" > script.py
[3] C:\ex>python -c "import script"
old
[4] C:\ex>script
old
[5] C:\ex>echo print "new" > script.py
[6] C:\ex>script
old
[7] C:\ex>python -c "import script"
new
[8] C:\ex>script
new
Even though script.py contains new (line 5), script in line 6 runs the .pyc
generated by line 3.
To fix this problem, put .py and .pyw extenstions ahead of .pyc and .pyo in
PATHEXT.
Hope this helps,
Mark
More information about the Python-list
mailing list