PyCharm doesn't recognize installed modules

Some of the modules I'm trying to import in PyCharm are not recognized (as shown in the picture). The weird thing is that for example, PyCharm is able to recognize 'linkage' from scipy.cluster.hierarchy', but not 'zscore' from 'scipy.stats', meaning that 'scipy' is indeed installed.

I'm using PyCharm 2020.1 and Python 3.7.7

I already tried:

  • Uninstalling and installing PyCharm.
  • Uninstalling and installing Python 3.7.7.
  • Configuring my project interpreter from the start and installing all the packages.
  • Using a different version of Python (3.8.2).
  • Checking the Interpreter paths.
  • Using a virtual environment in the project (venv folder).
  • Making sure the interpreter I'm using matches the python interpreter in the Python console settings.

Any suggestions are welcomed.

Thank you.

 

 

7 comments
Comment actions Permalink

Yoni Itzhak how did you resolve this issue? I have the same problem.

0
Comment actions Permalink

For me I found a solution.

I found out, that `__init__.py` file were not shown as python files in project tree. The issue was that `__init__.py` was included in  Settings --> File Types --> "File type auto-detected by file content". Removing it from there solved the issue

0
Comment actions Permalink

I have installed a package editable with 'pip install -e .' and even when the script ran correctly, the editor didn't sometimes (emphasis in sometimes) didn't recognize the package. Just for clarification, if I imported the module from python console in dataspell it worked without issues.

After a lot of attempts, the following steps solved my issue.

From this folder organization:

\root directory <-- that was an attached directory in dataspell

---\directory 1

------\python_script.py  <-- script using my_package

...

---\my_package <-- that was my editable package  (inside root_directory), installed with pip

------\__init__.py

------\python_script.py

 

went to this:

\root_directory <-- that was an attached directory in dataspell

---\directory 1

------\python_script.py  <-- script using my_package

...

my_package_folder. <-- that was my editable package  (NO LONGER inside root_directory), AND OPENED WITH FILE->OPEN (NO LONGER ATTACHED DIRECTORY)

------\__init__.py

------\python_script.py

 

After that, I have been able to edit my editable package and my scripts, no more import errors in screen and I can go to source from my script.

 

0
Comment actions Permalink

As for my last answer, do anyone know if this is a "problem" with python itself (or just how it works) or if it is an issue with dataspell?

0
Comment actions Permalink

After closing and opening again Dataspell, the damn problem has returned as new.

0
Comment actions Permalink

Hi Buttonpol,
Could you please report it to https://youtrack.jetbrains.com/issues/DS and provide an example project along with steps for reproducing the problem?
We'll look into it.

0
Comment actions Permalink

I've tried again several times and found a workaround: If I

  1. detach the source folder of the module I'm maintaining

  2. just having attached my folder containing the scripts importing those modules)

  3. go to Interpreter Settings/show all Python interpreters

  4. Delete the interpreter and accept

  5. add the conda virtual environment with my editable module

  6. and NO attaching the module folder

after that, the script editor works as expected

 

Issue has been reported with this info, DS-3581

0

Please sign in to leave a comment.