How to convert existing directory into a python package in Pycharm4

23,639

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 you all 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.

Share:
23,639
wolfgang
Author by

wolfgang

Updated on July 17, 2022

Comments

  • wolfgang
    wolfgang almost 2 years

    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

    enter image description here



    I've Tried adding the directory to "paths"

    enter image description here

    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

    enter image description here