Python source code is automatically compiled into Python byte code by the CPython interpreter. Compiled code is usually stored in .pyc files, and is regenerated when the source is updated, or when otherwise necessary.
Questions tagged [pyc]
195 questions
1295
votes
12 answers
If Python is interpreted, what are .pyc files?
Python is an interpreted language. But why does my source directory contain .pyc files, which are identified by Windows as "Compiled Python Files"?

froadie
- 79,995
- 75
- 166
- 235
495
votes
3 answers
What do the python file extensions, .pyc .pyd .pyo stand for?
What do these python file extensions mean?
.pyc
.pyd
.pyo
What are the differences between them and how are they generated from a *.py file?

Yanki Twizzy
- 7,771
- 8
- 41
- 68
243
votes
9 answers
Is it possible to decompile a compiled .pyc file into a .py file?
Is it possible to get some information out of the .pyc file that is generated from a .py file?

Howard
- 2,431
- 2
- 15
- 3
101
votes
2 answers
When are .pyc files refreshed?
I understand that ".pyc" files are compiled versions of the plain-text ".py" files, created at runtime to make programs run faster. However I have observed a few things:
Upon modification of "py" files, program behavior changes. This indicates that…

Aaron Schif
- 2,421
- 3
- 17
- 29
82
votes
10 answers
Remove .pyc files from Git remote repository
Accidentally, I have pushed the .pyc files to the master repository. Now I want to delete them but I can´t do it. Is there any way to remove them directly from the Bitbucket site?

ePascoal
- 2,362
- 6
- 26
- 44
53
votes
4 answers
Changing the directory where .pyc files are created
Is there a way to change the directory where .pyc file are created by the Python interpreter? I saw two PEPs about that subject (0304 and 3147), but none seems to be implemented in the default interpreter (I'm working with Python 3).
Did I miss…

Scharron
- 17,233
- 6
- 44
- 63
29
votes
2 answers
Running without Python source files in Python 3.4
I'm trying to run a Python application without keeping the .py source files around, and only relying on the .pyc compiled files. However, I am getting import errors when I remove the .py source files. This functionality is working in Python 2.7, but…

Matt Dodge
- 10,833
- 7
- 38
- 58
27
votes
1 answer
How to hide .pyc files when you enter `ls` in bash
When I perform ls in bash, I always see too many *.pyc files. Is there any way to hide these files?

user2566808
- 291
- 3
- 4
26
votes
1 answer
Why are .pyc files created on import?
I've seen several resources describing what .pyc files are and when they're created. But now I'm wondering why they're created when .py files are imported?
Also, why not create a .pyc file for the main Python file doing the importing?
I'm guessing…

bbill
- 2,264
- 1
- 22
- 28
24
votes
6 answers
Make Python ignore .pyc files
Is there a way to make Python ignore any .pyc files that are present and always interpret all the code (including imported modules) directly? Google hasn't turned up any answers, so I suspect not, but it seemed worth asking just in case.
(Why do I…

Ryan Gabbard
- 2,269
- 2
- 24
- 37
22
votes
2 answers
How hard to reverse engineer .pyd files?
After reading How do I protect Python code? , I decided to try a really simple extension module on Windows. I compiled my own extension module on Linux before, but this is the first time I compiled it on Windows. I was expecting to get a .dll file,…

yasar
- 13,158
- 28
- 95
- 160
18
votes
3 answers
Why is the 'running' of .pyc files not faster compared to .py files?
I know the difference between a .py and a .pyc file. My question is not about how, but about why According to the docs:
A program doesn’t run any faster when it is read from a .pyc or .pyo
file than when it is read from a .py file; the only thing…

OrangeTux
- 11,142
- 7
- 48
- 73
18
votes
2 answers
How to prevent python from using orphaned .pyc files? (ones with no matching .py files)
Once in a while I run into a very difficult-to-debug problem: there's a leftover .pyc file somewhere in my $PYTHONPATH, and the matching .py file has been moved to somewhere else that's later in $PYTHONPATH - so when I try to import the module, the…

weronika
- 2,561
- 2
- 24
- 30
17
votes
2 answers
How to find out the magic number for the .pyc header in Python 3
Python bytecode (.pyc) files have a header that starts with a magic number that changes between Python versions. How can I (programmatically) find out that number for the current Python version in order to generate a valid header? I'm currently…

sepp2k
- 363,768
- 54
- 674
- 675
17
votes
3 answers
What are the limitations of distributing .pyc files?
I've started working on a commercial application in Python, and I'm weighing my options for how to distribute the application.
Aside from the obvious (distribute sources with an appropriate commercial license), I'm considering distributing just the…

leedm777
- 23,444
- 10
- 58
- 87