PyCharm unresolved reference when importing from t

2019-05-23 07:03发布

When I just created a new project I had two py files - main.py and functions.py - in the project folder "my project". In main.py I imported functions.py and it worked fine. But then I created some folders in "my project" folder and put main.py and functions.py in one of them. They are still in the same folder, but in main.py it says that functions.py is an unresolved reference.

P.S. Using PyCharm on macos

1条回答
趁早两清
2楼-- · 2019-05-23 07:38

Simple answer: you should make a package in your directory tree and PyCharm will pick it up easily.

project_root
├── my_project
│   ├── __init__.py
│   ├── main.py
│   ├── functions.py

Open project_root in PyCharm and these imports should work correctly:

from my_project import functions

or

import my_project.functions
# you can also do 'import my_project.functions as functions'

my_project.functions.do_something('argument')
查看更多
登录 后发表回答