.py to .pyc

Peter Hansen peter at engcorp.com
Fri Sep 6 08:55:40 EDT 2002


andrea.baglioni at redturtle.net wrote:
> Hi everybody,
> 
> I'm a python newbie and i've a problem.
> 
> I want to compile a python file called File.py and i want to produce a file
> called File.pyc, so i do
> 
> python File.py

Actually, that won't do it.  Python only caches the bytecode in a .pyc
file for modules imported by the main routine.  Even if the above
worked properly, it still wouldn't leave you with a .pyc.  Besides,
why do you care about the .pyc anyway?  It's just an optimization
that Python even creates it for you in some cases.

That said, you should be able to get one by just running the interactive
prompt and doing "import File", if File.py has no errors.

> I always find the following error:
> 
> Traceback (most recent call last):
>   File "File.py", line 18, in ?
>     import Globals, StructuredText, string, utils, re
> ImportError: No module named Globals
> 
> Can anybody help me to find the problem? I think it's a problem of
> $PYTHONPATH and $PYTHONHOME but i'm not sure.

Why do you think that's the problem?  It seems more like that the
problem is that you are trying to import modules that are actually
part of the Zope infrastructure (if I recognize the above line),
and you'll likely have far more problems doing that than just what
you've faced so far.  Maybe some more background on what you are
trying to accomplish would help us answer more thoroughly.

-Peter




More information about the Python-list mailing list