Can I configure PyCharm so that when a new virtual env is created, its sys.path has a custom location automatically added?
Hi there,
I am building a local repository of useful modules, which will be stored in /Users/Rich/repo/ - the idea is that I will be able to import modules from this local repo into my projects.
I tend to create a new virtual environment for each Pycharm project, using Pycharm's tools to manage the environment. I would like to configure Pycharm so that whenever I start a new project and the venv is set up, the path 'Users/Rich/repo' is automatically added to sys.path, so that I can import useful modules with no further effort.
Is such a thing possible?
Thanks,
Rich
请先登录再写评论。
Hello Rich,
There is no dedicated automatic option for that in PyCharm, however, you can enable "Inherit global site-packages" option in a project creation https://www.jetbrains.com/help/pycharm/creating-empty-project.html
, add the desired path to sys.path and choose a base interpreter.
or
You can manually add a path to a list "Interpreter path" to an existing interpreter. Please see https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-reloading-interpreter-paths.html
Thanks. While I still think an automatic option would be useful, these suggestions are helpful.
Can I selectively inherit only some packages from the global site-packages? Or is it all or nothing?
Thank you once again for the feedback.
Hello Richard,
"Can I selectively inherit only some packages from the global site-packages? Or is it all or nothing?" - regrettably, no. However, you can split packages to different locations and add to "Intepreter path" only required ones.
You are welcome to submit a feature request at https://youtrack.jetbrains.com/issues/PY
Information on how to use YouTrack: https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications