[Solved] Warnings import local package: Unresolved references inspection

Completed

I created a git repository then I put my python code in the "./src" directory but I opened PyCham project in './'.

1. The PyCharm show me a horrible alerts about "Unresolved references inspection". I solved this adding "src.pkg" but if I run in my terminal it crash or if I use in other project it crash because I only use the pkg directory something like "pkg.html.tag.get.open_tags".

I need to keep the imports with the pkg path, this is the screenshot with an example file trying to import the pkg package.

 

2. I though about suppress the inspector but I have the second problem, the auto-complete fails.

3. This is my first __init__.py inside of pkg folder.

4. This is a screenshot in my terminal running from my home directory the example.py inside in a bit sub-folders and work successful if I keep the imports with 'pkg' vs 'src.pkg'.

 

 

4
3 comments

Have you marked src folder as 'sources root'? You need to do so in order for PyCharm to understand that it needs to resolve the modules starting with that folder.

13

I tried it but it is not that I'm looking because I loose the root path "./" and the main point is use in all the project the inspection tool, cleanup, see the status files with git colors, markdown, etc.

This is my in Git Hub: https://github.com/airvzxf/python-packages

I'm looking for something like say to PyCharm, -Hey! This is my root path for python compiler.- then compile since this path "./src"

 

There are my screenshots.

1. Settings window where I changed.

-    <content url="file://$MODULE_DIR$" />
+    <content url="file://$MODULE_DIR$/src" />


 

2. The module packages works but I lost all my root structure.

If you see in my last screens I had the folder "versions", I tried and if I have more than hone folder at the same hierarchy with the ./src the lost for example ./versions, ./tests, /resources, ./examples

0

Oh it works!
I got your idea and it works!

This is my in Git Hub: https://github.com/airvzxf/python-packages

 

Let me explain step by step:

1. Go to the settings "Ctrl+Alt+S" and select the next options:

2. Select the folder which want to convert into python sources in my case "./src" and tap in Source tag (Mark as..) then it added on the left panel also tap Apply or Ok.

3. It works! The inspector analysis passed, the example.py file detect my local package "pkg.degub.method" and it keep all my folders and files project. Right now the ./src folder has a blue icon folder in the project structure.

7

Please sign in to leave a comment.