Reputation: 1170
I have a file a.py in a directory somewhere inside the project, and in the same directory I have b.py. Inside a.py I want to be able to do:
import b
This works in Python, but Pycharm doesn't recognize it. Is there a way to make Pycharm always recognize import relative to the directory of the importing file?
EDIT: to clarify the issue, I already have sources root defined, and a.py and b.py are not at the top level. Here is a screenshot showing the issue:
EDIT 2: based on the comments, this question is invalid and I should not be importing code in the way described.
Upvotes: 1
Views: 294
Reputation: 1039
You can do import .b
.
Reference: https://docs.python.org/3/reference/import.html#package-relative-imports
Upvotes: 0
Reputation: 2756
Right click on the folder that you're working on
Select "Mark directory as" > "Sources Root"
Upvotes: 1
Reputation: 51
Well this a feature with pycharm already, just mark the source root for your project and pycharm will take care of the rest
Upvotes: 0