2

A rookie question here:

I have a PY code and compiled it to create a .pyc. I would want to use this pyc file instead of PY.

I am running the PY file using external program. When the PY exists in the folder everything works perfect. However when I remove the PY file and simply use the pyc I get error:

IOError: [Errno 2] No such file or directory: 'E:/data/test/tech.py'

Whereas I have a tech.pyc lying around in the same folder.Any ideas what could be the issue here?

user741592
  • 875
  • 3
  • 10
  • 25
  • 1
    Did you try to run it or import it? In any case how exactly did you do that? – Emilia Bopp Apr 04 '14 at 09:15
  • @msvalkon I think you can, see http://stackoverflow.com/questions/9913193/is-it-possible-to-import-a-compiled-python-file – Emilia Bopp Apr 04 '14 at 09:16
  • Ah, I'll refphrase. You *can* import the `.pyc` but I cannot understand what the benefit could be. It think it should be made clear that unlike a compiled language in which a program can be compiled into an executable binary and distributed "without" any concern, python `.pyc` do not serve that purpose. – msvalkon Apr 04 '14 at 09:19
  • I moved a step ahead now but when using PYC i get this error:SyntaxError: Non-ASCII character '\xf3' in file tech.pyc. When my PY works as expected why pyc is an issue? – user741592 Apr 04 '14 at 09:51

1 Answers1

7

Normally, python is not compiled. The .pyc files are only a performance optimization that improve loading times.

Python is looking for the .py file because it always checks that first. If a .pyc file is newer than its corresponding .py file, it will then use the .pyc file. If the .py file is newer it will create a new .pyc file.

Martijn
  • 11,964
  • 12
  • 50
  • 96
jnnnnn
  • 3,889
  • 32
  • 37