pycharm PYTHONPATH

Hi brandenju! I believe os.chdir doesn't affect PYTHONPATH so changing your working directory at runtime to resolve imports make little sense. One can edit PYTHONPATH with sys.path object if needed.

PyCharm refuse to read it

Could you please specify what exactly happened? Do you receive an unresolved reference error, ImportError during the runtime or both?

it's in my current directory

Is this directory a project root? If it's not then the problem seems to be clear - when running a file in the terminal your current working directory is added to the PYTHONPATH, this is not the case in PyCharm - by default, only the project root is added to PYTHONPATH. The basic workaround here is to mark lr_utils.py folder as Sources Root by right click in the Project window.

All source roots are added to PYTHONPATH.

原文地址:https://www.cnblogs.com/ExMan/p/10432734.html