PyCharm Fails to resolve references to installed modules and even built-ins

Answered
from __future__ import print_function
from builtins import input as input
import getpass

from sqlalchemy.exc import OperationalError
from terminaltables import SingleTabl

I am using a virtualenv generated by PyCharm itself. I have tried using my own virtualenv, a pipenv interpreter, and even the base python interpreter.

I have tried uninstalling, deleting my .idea folder, deleting the files in %appdata%, deleting the install directory, and reinstalling. I then set up a new virtualenv and installed packages. I have tried every option in the Project Interpreter outside of Conda. I have tried invalidating caches and restarting.

PyCharm still does not resolve references to *any* installed packages, and cannot find some built-in packages such as json and getpass.

 

9 comments

For the above snippet, the following errors are occuring:

unresolved reference __future__

unresolved reference print_function

No module named getpass

unresolved reference sqlalchemy

unresolved reference OperationalError

unresolved reference terminaltables

unresolved reference SingleTable

 

 

0

I would like to change this issue to a new Bug Report.

PyCharm does not set the Content Root to the site-packages directory when setting the project interpreter.

This wasted almost an entire day. Please add this to the Very Important bug list.

1

Hi!

It seems you have found the root cause for the issue. Can you please provide a full steps to reproduce the issue from scratch? Starting from creating a new project.

The following steps have NOT reproduced the issue for me:

1. Create new project with the new Virtualenv

2. Paste the example from above

3. Install sqlalchemy and terminaltables modules, and wait for PyCharm to index

4. Unresolved error does not apper

0

Hi,

This was a reoccurring issue up until I set the Content-Root. Every time PyCharm would update itself with the 'elevator' this would happen. I would try to break it again but I prefer not to waste time with this bug anymore.

0

Understood. Yes, things like that can happen between updates, I'll keep in mind to check content root if someone else will have the same issue.

0

A similar issue here.

from __future__ import print_function

Unresolved reference '__future__'
Unresolved reference 'print_function'

There is a similar issue with half of standard library modules, too:

import zipfile

Unresolved reference 'zipfile'

It seems to have started with some update, I have no other details.

0

@Peter

Does not reproduce for me. I'm testing on PyCharm 2019.1.3, and tried both Python 2 and Python 3.

Can you please do the usual troubleshooting steps of **File > Invalidate caches / restart**, and/or deleting and recreating your project interpreter? Which interpreter do you use?

0

Andrey,

I apologize for filing my report as it was not justified. Due to some company-wide decisions I am using an interpreter wrapper (a simple Bash script which modifies some environment variables and launches the python executable with correct arguments). Setting this wrapper as my Project Interpreter in Settings -> Project -> Project Interpreter makes PyCharm recognize only some of the standard library modules - other modules are underlined as unrecognized. I was mistakenly thinking that this strange behavior was a result of some past PyCharm update a I tried to find a similiar bug report here on intellij-support.

However, could you advice me on how PyCharm learns the system paths related to the selected interpreter? If it is by calling the interpreter somehow maybe I could modify my wrapper to pass the correct results.

Thank you,
Peter

0

PyCharm constructs interpreter paths based on the sys.path of the given interpreter. Doesn't IDE report your interpreter as invalid? Which entries do you have in interpreter paths?

0

Please sign in to leave a comment.