Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm: always mark venv directory as excluded

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?

like image 672
wim Avatar asked Aug 31 '17 16:08

wim


People also ask

How do I ignore a folder in PyCharm?

PyCharm allows you to exclude directories from consideration when searching and refactoring. You can exclude a directory by right-clicking on it and selecting Mark Directory as → Excluded.

How do I remove VENV from PyCharm?

You can clean out old PyCharm interpreters that are no longer associated with a project via Settings -> Project Interpreter, click on the gear in the top right, then click "More". This gives you a listing where you can get rid of old virtualenvs that PyCharm thinks are still around.

Does PyCharm automatically create virtual environment?

PyCharm can create a virtual environment for your project based on the project requirements.


2 Answers

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.

like image 83
nanotek Avatar answered Sep 22 '22 14:09

nanotek


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.

like image 27
bad_coder Avatar answered Sep 22 '22 14:09

bad_coder