Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm unresolved reference when importing from the same folder

Tags:

python

pycharm

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

like image 775
AndSolomin34 Avatar asked Jul 12 '26 09:07

AndSolomin34


1 Answers

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')
like image 137
kevins Avatar answered Jul 15 '26 06:07

kevins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!