[英]Using PYC file instead of a PY
A rookie question here: 一个菜鸟问题在这里:
I have a PY code and compiled it to create a .pyc. 我有一个PY代码,并将其编译为.pyc。 I would want to use this pyc file instead of PY. 我想使用此pyc文件而不是PY。
I am running the PY file using external program. 我正在使用外部程序运行PY文件。 When the PY exists in the folder everything works perfect. 当文件夹中存在PY时,一切正常。 However when I remove the PY file and simply use the pyc I get error: 但是,当我删除PY文件并仅使用pyc时,出现错误:
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? 我在同一个文件夹中有一个tech.pyc,有什么想法可能是这里的问题吗?
Normally, python is not compiled. 通常,不会编译python。 The .pyc
files are only a performance optimization that improve loading times. .pyc
文件仅是一项性能优化,可以缩短加载时间。
Python is looking for the .py
file because it always checks that first. Python正在寻找.py
文件,因为它总是首先检查该文件。 If a .pyc
file is newer than its corresponding .py
file, it will then use the .pyc
file. 如果.pyc
文件比其相应的.py
文件新,则它将使用.pyc
文件。 If the .py
file is newer it will create a new .pyc
file. 如果.py
文件较新,它将创建一个新的.pyc
文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.