Hi all,
I meet import error in pycharm since I import at a folder which is parallel to the target package trainer. I tried to use relative import, but it doesn’t work.
How can I resolve that and let the red lines disappear?
Hello,
welcome to the Python forum.
Assuming that you wanted to add the module trainer that is located in an adjacent directory not in the path of your project directory, you can do something like this:
import sys
sys.path.append(r'C:\folder1\folder2\')
This assumes that the module trainer is located:
C:\folder1\folder2\trainer
Here, we add the directory at runtime.
code indeed works there, but I just want to remove the red lines.
Click the motor icon on the upper right-hand corner. The Settings window will appear. Is the trainer library module listed? If it is, is it an older version? If so, click it to highlight it and hit the up arrow button to upgrade to the latest version. If it is not listed (maybe you have it in a related path), install it so that it is listed for this particular interpreter environment.
To add it, click the “+” button. The Available Packages window will appear. Start typing trainer and it should automatically appear in the list. Then click the Install Package button.
Give that a try and see if it solves your issue.
