Reputation: 7799
I have an option to create a python package
in PyCharm in the project directory
and when i use import newpackage
PyCharm Recognizes this.
I'm using PyCharm4, and when i try to "refractor" a directory to a package, i can't because the button is DISABLED. i can only see the convert to python module option
I've Tried adding the directory to "paths"
And Still No Success in getting PyCharm to recognize import
statements
I'm using PyCharm4
My Question again,
How can i convert a directory into a python package so that PyCharm will not show an error during import
statements
Edit
I do have an __init__.py
file inside the child directory. still no luck
Edit2 @joran
I've added the error screen like you requested, you can see the red underline marking the error
Upvotes: 8
Views: 35218
Reputation: 1126
The reason you can not import from crawler
is that crawler
is not a python package. Its just a directory (as you already know)
It doesn't seem worth your time to troubleshoot what may be a bug in the IDE, when all you need to do is create the empty __init__.py
yourself.
Having the __init__.py
inside a child directory is not enough. Each directory needs its own __init__.py
Manually adding an empty file called __init__.py
to that top level folder crawler
folder will turn this into a python package.
Once done, refresh your Pycharm project.
Upvotes: 10
Reputation: 23
You need to set the project directory as a source root (right click on it > Mark directory as > Source Root), and then synchronize the project !
Upvotes: -1