Very frustrated--PyCharm says local import is unresolved reference




PyCharm is claiming a local import is an unresolved reference, but when I run the script through Run/Debug mode (yes, while the import is still highlighted as red) the script runs fine.  I tried restarted PyCharm to see if the error would go away but this hasn't resolved it.  I am using the follow PyCharm:

PyCharm 2018.1.4 (Professional Edition)

The structure of my project is like this:




In, I have "import foo".  The current working directory for is also set to root/scripts1/.  However, PyCharm complains that "import foo" is an unresolved reference and underlines the whole thing in red.  Nevertheless, I can still execute with the foo import when using the Run/Debug mode.  PyCharm wants me to do "from . import foo"  but this actually breaks my script!  root/scripts1 is not a Python module/package and does not have an (or in the parent dir either).  

Why is this happening and how do I fix it?  


Comment actions Permalink

have you tried the '.' immediately before foo?

import .foo

You can also suppress warnings:

Comment actions Permalink

I am getting the same error, I was using version 2017.2, now updated Pycharm to 2018.3.5 and still get the same error. Indeed very frustrating and more frustrating is the lack of answer for this problem. Any news?

Comment actions Permalink

@Pedro Quintas

The latest version is 2019.1.1 , please update (, and if the issue is still reproduced, provide the code snippet which can be used to reproduce the issue.

Comment actions Permalink

Hello, I am using PyCharm community version:

PyCharm 2019.2.5 (Community Edition)
Build #PC-192.7142.56, built on November 19, 2019
Runtime version: 11.0.4+10-b304.77 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 974M
Cores: 4
Non-Bundled Plugins: CMD Support, izhangzhihao.rainbow.brackets, org.intellij.plugins.markdown, some.awesome

I have a file called "", and I import it from a file in the same directory called "". I am still getting this issue ("No module named p01", in file 


Thank you!

Comment actions Permalink

@Dan Katzuv

>I have a file called "", and I import it from a file in the same directory called "". I am still getting this issue ("No module named p01", in file 

Are those files located in sub-directory (not project root)? If yes, please try marking this directory as Sources:

Comment actions Permalink

Andrey Resler Yes! Your suggestion to set the project sub-directory with the python files as "Sources Root" is what finally allowed PyCharm to acknowledge the imports. That totally makes sense. Thanks!

Comment actions Permalink

Ah! I have been having this problem for a long time too and it means that you miss out on all of the autocomplete and inspections... (with ugly, red underlined imports...).. Marking the top level directory as "Sources Root" has done it for me too! Thank goodness for that!

Comment actions Permalink

This is still affecting me. Project structure is as follows:

project-name -> 
src ->
package ->
other_package ->

If I try to do this inside

from src.other_package import other_script

I get an "Unresolved reference 'other_script' "

This means I don't get any autocomplete features/help with parameter names, etc.

If I remove the from other_package, this problem goes away but then setuptools doesn't treat other_package as a package!

Any ideas?

Comment actions Permalink

I'm just a user same as you but I believe you need to nest some_package inside of package to do relative imports as you are wanting to do. It's just how python works I'm afraid.

So you need to change the structure of your app in line with a single heirarchy / tree and only import from same level of tree or higher. You leaves cannot import from other leaves of the tree.

Hope this helps :)

Comment actions Permalink

Then you should use relative imports after restructuring. Like this

from .other_package import other_script

Everything will work out better for you that way.


Please sign in to leave a comment.