Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm not adding sources root to `sys.path`

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?

like image 319
David Parks Avatar asked May 09 '18 17:05

David Parks


People also ask

What is source roots in PyCharm?

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.

How do I change the path in PyCharm?

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.


1 Answers

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.

like image 64
David Parks Avatar answered Oct 28 '22 20:10

David Parks