where are the .pyc files? where are the .pyc files? python python

where are the .pyc files?


A *.pyc file is created for imported modules, and they are placed in the same directory containing the .py file. However... no .pyc file is created for the main script for your program. In other words... if you call "python myscript.py" on the command line, there will be no .pyc file for myscript.py.

This is how Python 2.x behaves. However, in Python 3.x the .pyc files are saved in a __pycache__ directory. See David Glick's answer for details.

[edit: Added note about Python 3.x.]


In Python < 3.2, the .pyc files are placed in the same directory as the .py file.

In Python 3.2, the compiled files are placed in a __pycache__ subdirectory, and are named differently depending on which Python interpreter created them. (This can be useful to people importing the same Python modules from multiple versions of Python.) See http://docs.python.org/dev/whatsnew/3.2.html#pep-3147-pyc-repository-directories for more information.


They are always created in whatever directory contains your .py files. Also, they are created for imported modules, not files that you directly run.

If you want to create .pyc files, boot up a Python interpreter and just import the modules of your choosing.