PyCharm: always mark venv directory as excluded

11,732

Solution 1

In File > Settings > Project: > Project Structure at the bottom is Exclude files: You can put something in there like

venv or venv;coverage.xml (given your comment)

It doesn't seem to recognize paths (e.g. foo/venv), but this does what you requested.

Solution 2

You can globally exclude a directory in PyCharm by following the Breadcrumb trail:

Settings > Editor > File Types > Ignore Files and Folders:

At the bottom is a text box where you can input the symbolic link ./venv relative to your projects base directory, highlighted in the picture:

enter image description here

After that, new projects have ./venv excluded by default. You don't need to repeat the above steps for new projects. In use, "Find in Path" shows:

enter image description here

P.S. I also started keeping my venvs inside their project directories. Once you have dozens of projects it just becomes convenient.

Share:
11,732
wim
Author by

wim

Hi from Chicago! Python dev with interest in mathematics, music, robotics and computer vision. I hope my Q&A have been helpful for you. If one of my answers has saved your butt today and you would like a way to say thank you, then feel free to buy me a coffee! :-D [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo *Click*

Updated on June 05, 2022

Comments

  • wim
    wim about 2 years

    In Python 3, I've moved away from creating virtualenvs in ~/.virtualenvs and towards keeping them in the project directory ./venv

    However now search results in every PyCharm project include results from venv subdirectories, until you manually right-click and exclude them from the project.

    How to omit directories named venv from PyCharm indexing/searching, globally?

  • wim
    wim almost 7 years
    That menu applies to the current project. The question is about creating global exclude settings.
  • axd
    axd over 6 years
    What seems to work is to manually mark such folders as excluded in Project Structure > (select a project) > right-click on the desired directories in the central pane so that those names are added in the right-hand pane (PyCharm 2017.3)
  • wim
    wim over 4 years
    This looks promising, but it has the unacceptable side-effect that every 3rd-party project installed to the venv gets a red squiggle underneath and cannot be browsed into with ctrl+click. PyCharm now thinks Cannot find declaration to go to, even though they are actually installed in the project's venv. Any idea about that?
  • bad_coder
    bad_coder over 4 years
    @wim Good point! Couldn't reproduce, my 3rd party libraries(projects?) are pip installed. "Go to declaration" or ctrl+click work opening the definition, no red scribble, (and the internals don't pollute search.) Side-effect fix: venv path/file structure is stable, exclude the list of core files in the text box; Anything besides core venv files isn't global anyway, and can be excluded/hidden case-by-case using the method in the other answer.