Created a project in PyCharm with one file module1.py:

print('Hello module World!') 

Run the Run button.

Why in the project directory does not create a file with the bytecode module1.pyc?

    3 answers 3

    Why in the project directory does not create a file with the bytecode module1.pyc?

    Because in Python 3, such files are written to the __pycache__ directory (see PEP 3147 ), which your IDE will most likely hide so as not to trash the appearance of the project directory.

    If you start a module by passing it from the command line (or if your IDE does it for you): python ваш_модуль.py , then it is recompiled each time ( .pyc not created) . Compare this with running python -mваш_модуль that imports ваш_модуль and therefore the .pyc file in the __pycache__ directory can be written.

    Also check if you have rights to create a subdirectory (from which user python is running). You can try compiling the modules yourself:

     >>> import py_compile >>> py_compile.compile('ваш_модуль.py') 

    Another option is that the creation of .pyc disabled, for example, due to the non-empty PYTHONDONTWRITEBYTECODE environment variable or python -B command line option.

      Perhaps, in the Pycharm settings you have enabled ignoring these files. Like for example with me. enter image description here Here is the documentation for customizing the display https://www.jetbrains.com/help/pycharm/2016.1/file-types.html .

      I do not understand why you need them. On the deployment they do not affect the version control system, either.

      • I need this for a general understanding of how a language works with a virtual machine and, in particular, PVM. - Alexey Nikolaev
      • I understand that ignoring the type of .pyc files is used only for the convenience of working with the project, since they are not intended to interact with humans. Those. just hiding from the project tree. But this does not affect the creation of such files. - Alexey Nikolaev
      • @ AlekseyNikolaev yes, the files are simply hidden, they do not cease to exist. just don't litter the IDE explorer - while1pass
      • I achieved that the file module1.cpython-35.pyc was created in the __pycache__ folder. But only by running the interpreter from the command line. I will continue to understand how to work with bytecode in the IDE. - Alexey Nikolaev
      • By the way, one bytecode use case is to distribute .pyc files instead of .py to complicate reverse engineering. It is possible to have a file called "spam.pyc" (or "spam.pyo" when -O is used) without a module "spam.py" in the same module. This can be used to make it a moderately hard to reverse engineer. - Alexey Nikolaev

      As far as I know, * .pyc files are created when importing a module.

      module2.py:

       import module1.py 

      Get module1.cpython-35.pyc