问题描述
在python2中有两种生成pyc的方法:
1。
import py_compile
py_compile.compile("file.py")
2。
python -m compileall ./
python3怎么办? 我尝试了上述两种方法,都没有在python3中生成.pyc文件。 请帮忙。
1楼
谢谢@meissner_
import py_compile
py_compile.compile("file.py") #compiles single file named file.py
python -m compileall ./ #combines all programs under current directory
两种方法都可以在Python2和Python3中使用。 Python2和Python3的唯一区别是:
Python2在同一目录中生成.pyc文件,而
Python3在同一目录中名为__pycache__的文件夹中创建它。