Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import directory into pycharm

Tags:

python

pycharm

I am trying to import a legacy project into pycharm for debugging. The directory structure looks like:

top folder ---> folder one

top folder ---> folder two

The problem is that programs in the sub-folders use:

 import top 
 from top import module  

Pycharm returns the error: "No module named top"

How can I fix this?

like image 902
user2002858 Avatar asked Aug 20 '13 19:08

user2002858


1 Answers

First thing to make sure is to do what Games said, you need to make sure each folder that is representing a package is done by putting a __init__.py file which is a empty python file named exactly __init__.py that tells the interpreter that the folder is a python package.

Second thing to look for is that pycharm likes to complain about imported code if PyCharm does not know about that directory. Go into the Project Interpreter Configuration and go to Paths and add the path references that are not in the project or directly under the interpreter.

One other thing to add, is to set the source root of your project code by right clicking the folder that represents your root and clicking the 'Mark Directory as...' > 'Source Root'.

like image 165
BrokenRobot Avatar answered Sep 17 '22 20:09

BrokenRobot