.py to .pyc

Kerim Borchaev warkid at storm.ru
Fri Sep 6 08:17:15 EDT 2002


Hello andrea,

Friday, September 06, 2002, 12:25:14 PM, you wrote:

abrn> Hi everybody,

abrn> I'm a python newbie and i've a problem.

abrn> I want to compile a python file called File.py and i want to produce a file
abrn> called File.pyc, so i do

abrn> python File.py

abrn> I always find the following error:

abrn> Traceback (most recent call last):
abrn>   File "File.py", line 18, in ?
abrn>     import Globals, StructuredText, string, utils, re
abrn> ImportError: No module named Globals

abrn> Can anybody help me to find the problem? I think it's a problem of
abrn> $PYTHONPATH and $PYTHONHOME but i'm not sure.

abrn> Please...help!

abrn> Thanx in advance

abrn> Andrew

You could use py_compile module like this:

##test.py############
fname = 'test_module.py'
src = 'import this_module_does_not_exist\n'
open(fname, 'w').write(src)
import py_compile 
py_compile.compile(fname)
print `open(fname+'c').read()`
#############

so just do:
import py_compile
py_compile.compile('File.py')

Best regards,
 Kerim                            mailto:warkid at storm.ru






More information about the Python-list mailing list