Src layout to dispense .src prefix in imports? Activate venv in PyCharm terminal for development installs

Update / Workaround

One can follow the steps in this link to mark a folder as a source root. From the link:

Source roots the Source root icon contain the actual source files and
resources. PyCharm uses the source roots as the starting point for
resolving imports

This way we don’t have to install It or to change the path anymore (although It still feels kind of tricky to me)

1. Pycharm has a pip problem:

Whenever I run pip in the pycharm terminal It runs the system’s pip for some reason. You can check that with the which pip command. But if I run python -m pip It does the right thing.

2. It should actually recognizes the imports:

That being said, I really don’t know why pycharm can’t recognize the imports without the src. prefix. I cloned the `cryptography package from github and It recognizes It normally, the src folder is automatically added to path, but I don’t know how Yet.

Either way, your code works as expected without the prefix and Vim (using Pyright) recognizes It flawlessly. Even running It on pycharm actually works with all the import errors.

3. What to do now?

Until they fix It or I find a solution I’ll just add the src folder to my path in the interpreter settings manually, since I don’t want to install It (but I want to be able to peak and go to definitions).

If I really want to install the package I would do It in the terminal or inside pycharm using python -m pip install -e -v .

Leave a Comment