user741592
user741592

Reputation: 925

Using PYC file instead of a PY

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?

Upvotes: 3

Views: 3136

Answers (1)

jnnnnn
jnnnnn

Reputation: 4353

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.

Upvotes: 7

Related Questions