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.
请先登录再写评论。
Yoni Itzhak how did you resolve this issue? I have the same problem.
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
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.
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?
After closing and opening again Dataspell, the damn problem has returned as new.
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.
I've tried again several times and found a workaround: If I
detach the source folder of the module I'm maintaining
just having attached my folder containing the scripts importing those modules)
go to Interpreter Settings/show all Python interpreters
Delete the interpreter and accept
add the conda virtual environment with my editable module
and NO attaching the module folder
after that, the script editor works as expected
Issue has been reported with this info, DS-3581
i have the same issue
this is how i solve
1. find the location of the working directory(pycharm---file---setting---project---project structure)
2. find the location of the downloaded module(type pip show {module name} in command prompt )
3. copy the module from the location(location shown in command prompt)
4.paste the module in working directory location(paste in site-package inside lib)
I have a similar problem. I using custom modules that are inside a custom dir. This dir is added to PYTHONPATH env variable.
Now, PyCharm does not recognize those modules when I try to import to any file in my project.
Guess what. The same project/file I open in Visual Studio Code and everything works fine.
LUCCAS SCHMIGEL Did you try to add the custom dir into the interpreter paths? In case the issue persists, feel free to open a new request directly with us at https://youtrack.jetbrains.com/newIssue?project=PY
Miguel Monteiro thank you so much. That solved it!
For 2024.2.0.1 (Community Edition), this only happens for me if installing with pip as editable (
pip install -e ~/path_to_lib/
).If I do not install as editble, this issue does not occur.
I assume this is due to https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-reloading-interpreter-paths.html#view interpreter paths pointing at site-packages subfolder.
Hi Jason Mellone , have you tried to add
~/path_to_lib/
to interpreter paths list as suggested above?