Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does PyCharm store compiled files?

Tags:

python

pycharm

I'm new to PyCharm/Python, and can't figure out where the IDE stores compiled python *.pyc files.

Coming from the IntelliJ world, it is strange that I don't see any menu options to re-build the project, or build individual files.

I'm also unable to find any pyc files while searching the project directory, so basically, I've no idea whether successful compilation has happened at all, although the GitHub imported project is error free.

What can I do here?

like image 421
gabox01 Avatar asked Apr 13 '18 15:04

gabox01


1 Answers

Because most Python implementations are interpreted rather than a compiled, the compilation step happens when you run the code. This is why the PyCharm UI features a prominent "Run" button (▶️) but no compile button.

It is true that for CPython there is a compilation step which compiles from the Python code to bytecode, but this is an implementation detail. CPython 3 stores its cached compilation results in .pyc files in a directory called __pycache__. These files are automatically generated when a module is imported (using import module will result in a module.pyc file) but not when a normal program is run.

Lastly, as per @shmee's comment, it is possible to compile a source file with the py_compile module, but I should emphasise that this is not usually done or necessary.

Now, if you are worried about checking that your code is correct, in the interpreted language world we rely more strongly on testing. I would recommend that you investigate tests for your code (using pytest and the excellent test integration in PyCharm).

like image 134
chthonicdaemon Avatar answered Oct 19 '22 08:10

chthonicdaemon