Unwanted __init__.py being generated when moving scripts

Answered

 

Steps to reproduce:

  1. Create an empty Python project
  2. Create a directory (not a package)
  3. Create a Python file
  4. Move the file into the directory 

A

__init__.py 

file will be created in the directory.

How can I disable this behavior?

8
10 comments

Hi Claas Meiners! Disable Search for references option in move window:

0
Avatar
Permanently deleted user

Just a note that if you use a pip namespace https://packaging.python.org/en/latest/guides/packaging-namespace-packages/

Then moving a file within your sub package will add a __init__.py file to the namespace which will cause interference with the installed namespace in the virtualenv.

I don't think intellij should be adding __init__.py files for pre-existing folders, it's okay if the move creates folders though.

2
Avatar
Permanently deleted user

I am having the same issue and it is frustrating. Pycharm should not be adding an __init__.py file to a namespace package. Disabling "Search for reference" is not a good solution either because we typically want references to be updated.

4

Agreed, Pavel's solution above is like killing the patient to cure the cancer

2

Hey, is there a solution for this instead of disabling the "Search for reference"? 

 

0

Honestly, this is the type of stuff that makes me want to move to vim. This should 1000% be configurable as a setting and its incredibly debatable whether this should be a default. It is extremely easy to miss this and then all of a sudden you recursively have delete these unwanted files… 

0

Still no update? And why is this marked as `Answered`?

0

This hasn't been answered or fixed.

0

It's 2024 and we dont need __init__.py any more.  Do not create these files!  This should be such an easy fix, dissapointing no one has taken care of it already.

0

Still a damn problem.  Very frustrating.  Moving to VisualCode

0

Please sign in to leave a comment.