Re: Any way to not create .pyc files?



Lonnie Princehouse wrote:
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?

You could roll your package into a zip archive and then import that. For instance, keep your main.py out of the archive and put everything else in. Then, at the top of main.py:


import sys
sys.path.insert("network_path/package.zip")

import package
# do normal stuff with package here.

As long as you zipped up the package will all .pyc and .pyo files removed, Python will have no choice but to compile the files every time they are imported - unless I'm grossly mistaken Python won't put the pyc files into the zip archive, or modify any that were there already.

As far as the maintenance headache of distributing updated copies to individual workstations, IMO this just requires a little forethought and then it isn't a headache at all. Instead of the users starting the application directly, they could start a starter application that checks with the server to determine if local files need to be updated, and if so grab them and then start the main app. This actually removes headaches in the Windows world, where you can't drop-in updates to programs that are currently running.

What I've done in the past adds on to the starter application idea, and has the main application check to see if there are updates to the starter application, and if so pull those changes down upon exit of the main application. I just saved the file locations locally in an INI file.

--
Paul McNett
http://paulmcnett.com

.



Relevant Pages

  • Re: PEP 3147 - new .pyc format
    ... I only would need to worry about python source ... the .pyc files and just care about the source. ... if you suspect a bug in the compiler; ...
    (comp.lang.python)
  • Re: Python bytecode compatibility between interpreter versions
    ... Note that I specifically mentioned .pyc files vs. java class files, ... not Java the language/environment/platform vs. Python. ... > your platform. ... Perhaps one day .pyc files can work in such a manner. ...
    (comp.lang.python)
  • Re: PEP 3147 - new .pyc format
    ... I often end up renaming it multiple times ... I only would need to worry about python source ... the .pyc files and just care about the source. ... Forget about byte-code compiling, and just treat Python as a purely ...
    (comp.lang.python)
  • Re: Race condition when generating .pyc files
    ... Part of the code lives in one place, ... hosts when the module's .pyc file is generated. ... python source first. ... Inhibiting the generation of .pyc files altogether if that's even ...
    (comp.lang.python)
  • How would you improve this? (python precompiler)
    ... When python files are run by a user with write access to those ... If a user hasn't write access, the bytecode can't be ... and cleans up stray .pyc and .pyo files when the ... 'for' loop treats parts split by white space as unique items. ...
    (comp.unix.shell)