Get pycharm to stop adding content roots to projects

As of a few release ago (maybe 3-6 months?), pycharm has started adding 'external' content roots to my projects without me asking it to. When I manually remove these content roots, they reappear by themselves on certain actions. I think adding a new file to the project does this, possibly others. 

For some context, my 'project' is a large collection of closely related python packages which I integrate together as namespace packages. The fact that they are namespace packages, pycharm's intellisense has in of itself been somewhat hit and miss. It used to be next to useless across package (project) boundaries, but of late it seems to be working somewhat better.

The various packages (projects) in my project are all in the format that includes a and has all the sources in an src directory at the project root. They all get installed into a single virtual environment. Usually, I open only a small handful of packages (projects) together when I'm working on something. These projects would import from the other (unopened) projects, and to have them be present in intellisense is nice, but my project tree starts to look like this:

In this, the top-level "tendril-interests" seems to be the project name, and the "tendril-interests" just below it is the project directory and the only one I care about. Within it is a, an src/ folder, and a bunch of other boiler place. All the other src/ folders visible here are from other related projects, which pycharm decided I should have in my workspace. For comparison, below is what a 'regular', largely independent package looks like: 


This project has a roughly similar structure, without all the related projects. Note the project name appears only once and under it is directly the contents of the project root. This is what I want my other projects to look like.

As I open 3-4 packages, this gets progressively worse. Each open package has its own list of content or library roots other than itself, none of which I've added and none of which I want to see in this workspace. The navigation tree at this point becomes useless.

To make matters worse, I've noticed the following behavior:

  - When I go to a file using Ctrl + B or click on a reference in a traceback, the particular file it opens may not belong to the project itself, even if the project is open by itself. Very often, the highlighted and focused file in the project navigation pane is actually in one of the 'src' Content Roots which got auto-added. While doing so, the src folder gets un-collapsed and this happens for _every_ copy of that project's 'src' that got auto-added. Trying to figure out which project I'm actually poking at is next to impossible.

- It seems pycharm is allowing me to make changes to files in these auto-added content roots. When this happens, I don't get a warning saying that I'm editing an external file. At the same time, the relevant VCS roots don't get added though, so when I open the Commit pane changes can be missing. As a result, I end up needing to remember where my changes were (in a project with over 60 packages), open that particular project in pycharm (a rare effort), or cd to the project that got the change and git commit manually (the only viable approach, as long as I notice it in time).

My apologies for the verbose and possibly useless explanation. I don't quite know how to explain it. This has reached the point where pycharm itself is becoming unusable as a result. The package collection that causes this issue most acutely is here: , though I've seen it in others as well.

TL/DR : 

 - Make pycharm stop adding these content roots

 - Optional : Do this while allowing pycharm to index these other projects (which are installed in the same python virtual env, often using pip install -e .) so that intellisense still works. If I need to lose cross-package intellisense to make these things go away, though, I am willing to give it up. 



I'm very sorry, but I can't understand how to reproduce this problem.

Could you please share the precise steps on how to replicate this behaviour? 


I'll try to put together the minimal steps needed to reproduce this. Might take a few days though, since I'll probably need to do it on a VM or so. Pycharm seems to keep track of projects it knows about system-wide.

The setting I'm ideally looking for is something along the lines of "(Disable) Automatically add related content roots outside of the project path.", where related means either of :

   - dependency listed in / requirements.txt

   - namespace packages within the same namespace, so package paths are shared.


Two namespace packages, namespace-packageA and namespace-packageB, may have the following content:


|-namespace_name (importable as "import namespace_name")
| |-
| |- (importable as "from namespace_name import a"



|-namespace_name (importable as "import namespace_name")
| |-
| |- (importable as "from namespace_name import b"


Both files will have identical content, usually:

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)


Sorry for the delayed reply. 

We've successfully reproduced the problem and created an issue on YouTrack. Please vote for it to raise its relevance and receive updates regarding the fix status.


Thank you for the update. I have been tied up with development and was unable to trivially generate a minimal example which reproduces the issue. 


Please sign in to leave a comment.