简体   繁体   中英

How to convert existing directory into a python package in Pycharm4

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

在此输入图像描述

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.

您需要将项目目录设置为源根目录(右键单击它>将目录标记为>源根目录),然后同步项目!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM