In a run configuration in PyCharm I've check both:
Add content roots to PYTHONPATH
Add source roots to PYTHONPATH
But I can't import files relative to my sources root. This is a new installation of PyCharm (system rebuild) and an existing project & run configurations which worked before now fail.
In the Python Console I print the value of sys.path
and see my content root, but not the source root listed. I double check the Project Structure and see the directory src
is listed as a Source Folder appropriately.
When I run python at the console from the source root directory all imports work as expected.
Any idea what configuration I might be missing in PyCharm to cause this? Or perhaps my expectation is incorrect?
Source roots (or source folders; shown as ). These roots contain the actual source files and resources. PyCharm uses the source roots as the starting point for resolving imports. The files under the source roots are interpreted according to their type.
Change the location of IDE directoriesFrom the main menu, select Help | Edit Custom Properties. Specify paths with forward slashes /, including Windows paths (for example, C:/idea/system). After you restart PyCharm, it will use the new location of the corresponding directory.
I found the solution here:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000164624-SOLVED-pycharm-seem-to-fail-to-add-to-PYTHONPATH
Just delete the .idea
project directory and re-create the project to fix the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With