PyCharm not adding sources root to `sys.path`

2019-03-05 05:11发布

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?

1条回答
等我变得足够好
2楼-- · 2019-03-05 05:47

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.

查看更多
登录 后发表回答