<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/cpython-doesn-t-execute-your-py-file-directly-iodqx5ugs" -->

---
title: CPython doesn’t execute your .py file directly | daily.dev
description: CPython compiles Python source files to bytecode before execution, even when no .pyc file is written. The .pyc files in __pycache__ are just cached bytecode...
canonical: https://daily.dev/posts/cpython-doesn-t-execute-your-py-file-directly-iodqx5ugs
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: CPython doesn’t execute your .py file directly | daily.dev
og:description: CPython compiles Python source files to bytecode before execution, even when no .pyc file is written. The .pyc files in __pycache__ are just cached bytecode...
og:url: https://daily.dev/posts/cpython-doesn-t-execute-your-py-file-directly-iodqx5ugs
og:image: https://api.daily.dev/og/posts/iODqX5UGS.png
og:image:alt: CPython doesn’t execute your .py file directly
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# CPython doesn’t execute your .py file directly

**[Medium](https://daily.dev/sources/medium_js)** · 2 min read · 0 upvotes · 0 comments

## Summary

CPython compiles Python source files to bytecode before execution, even when no .pyc file is written. The .pyc files in __pycache__ are just cached bytecode for imported modules — not for directly-run scripts, since those only execute once. The cache filename encodes the interpreter version, and CPython validates it using file timestamps, size, or optionally a hash. Using dis.dis() reveals that even simple Python expressions compile into multiple bytecode instructions, which is a key reason CPython is slower than natively compiled languages like C — operations are resolved at runtime through Python's object model rather than compiled to fixed machine instructions.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://medium.com/@jegant/cpython-doesnt-execute-your-py-file-directly-d9e0fa717256>

## Similar posts on daily.dev

- [Write C Code Without Learning C: The Magic of PythoC](https://daily.dev/posts/write-c-code-without-learning-c-the-magic-of-pythoc-woxahty0c) · Towards Data Science · 0 upvotes · 0 comments
- [Speed-up Native Python Code using Cython](https://daily.dev/posts/speed-up-native-python-code-using-cython-chjwtqj9o) · Daily Dose of Data Science \| Avi Chawla \| Substack · 5 upvotes · 0 comments
- [PythoC: A new way to generate C code from Python](https://daily.dev/posts/pythoc-a-new-way-to-generate-c-code-from-python-hhhyci0hl) · InfoWorld · 2 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#cpython](https://daily.dev/tags/cpython)

[View this post on daily.dev](https://daily.dev/posts/cpython-doesn-t-execute-your-py-file-directly-iodqx5ugs)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"CPython doesn’t execute your .py file directly","url":"https://daily.dev/posts/cpython-doesn-t-execute-your-py-file-directly-iodqx5ugs","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/cpython-doesn-t-execute-your-py-file-directly-iodqx5ugs"},"datePublished":"2026-07-06T05:35:54.144Z","dateModified":"2026-07-06T05:37:07.514Z","description":"CPython compiles Python source files to bytecode before execution, even when no .pyc file is written. The .pyc files in __pycache__ are just cached bytecode...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/431a5183028037dc3e68902fe4be10c5?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/431a5183028037dc3e68902fe4be10c5?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Medium","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Medium","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/medium","url":"https://daily.dev/sources/medium_js"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/cpython-doesn-t-execute-your-py-file-directly-iodqx5ugs","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,cpython","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Medium","item":"https://daily.dev/sources/medium_js"},{"@type":"ListItem","position":3,"name":"CPython doesn’t execute your .py file directly"}]}
```

