If your own module is in the same path, you need mark the path as Sources Root. In the project explorer, right-click on the directory that you want import. Then select Mark Directory As and select Sources Root.
If your own module is in the same path, you need mark the path as Sources Root. In the project explorer, right-click on the directory that you want import. Then select Mark Directory As and select Sources Root.
So if you go to
-> Setting -> Project:My_project -> Project Structure,
Just the directory in which the source code is available and mark it as "Sources" (You can see it on the same window). The directory with source code should turn blue. Now u can import in modules residing in same directory.
python - PyCharm doesn't recognize installed module - Stack Overflow
"Module not found error" Pycharm Troubleshooting
PyCharm not "detecting" modules... possible pip issue?
In PyCharm's settings, you can configure the directories it looks in for installed modules. Maybe it's just looking in the wrong place? The option's rather hidden behind buttons with no name, so it's hard to describe, but this screenshot should give you an idea where to look:
http://imgur.com/PPqxBmE
More on reddit.comCan't import local modules in Pycharm
In my case, using a pre-existing virtualenv did not work in the editor - all modules were marked as unresolved reference (running naturally works, as this is outside of the editor's config, just running an external process (not so easy for debugging)).
Turns out PyCharm did not add the site-packages directory... the fix is to manually add it.
On Pycharm professional 2022.3
Open File -> Settings -> Python Interpreter, open the drop-down and pick "Show All..." (to edit the config) (1), right click your interpreter (2), click "Show Interpreter Paths" (3).
In that screen, manually add the "site-packages" directory of the virtual environment [looks like .../venv/lib/python3.8/site-packages (4) (I've added the "Lib" also, for a good measure); once done and saved, they will turn up in the interpreter paths.

The other thing that won't hurt to do is select "Associate this virtual environment with the current project", in the interpreter's edit box.
If you are using PyCharms CE (Community Edition), then click on:
File->Default Settings->Project Interpreter

See the + sign at the bottom, click on it. It will open another dialog with a host of modules available. Select your package (e.g. requests) and PyCharm will do the rest.
Hey everyone, I'm a beginner and could use some help. I installed a library, but Python isn't recognizing it. I've already tried using the pip install command in the terminal, but I still get the 'Module not found' error. What's weird is that other libraries like numpy and pandas work just fine. Does anyone know what could be wrong?
So, I've installed xlsxwriter via pip just fine -- scripts run no problem. My issue is that I can't find where the actual files are installed to (because PyCharm IDE doesn't detect that xlsxwriter is actually installed and has that annoying red underline)
So, as you can see in the attached picture, when I run pip uninstall xlsxwriter it is showing that it's installed in \lib\site-packages\xlsxwriter\ but that folder simply does not exist as far as I can tell, not even as a hidden directory.
In the end, I really just want PyCharm to stop underlining modules that are installed, but this appears to be the case with a few different modules and I just want to get to the bottom of it.
http://imgur.com/DCAMRSJ
http://imgur.com/jbxAecT
In PyCharm's settings, you can configure the directories it looks in for installed modules. Maybe it's just looking in the wrong place? The option's rather hidden behind buttons with no name, so it's hard to describe, but this screenshot should give you an idea where to look:
http://imgur.com/PPqxBmE
-
So the modules are installed, it runs but pyCharm says they are not ?
=> pyCharm read your package folder and cache the result. The pyCharm cache must not be up-to-date.
-
Or python does not run and throw an error 'package not there' ?
=> Do you have multiple interpreters (2.7/3.5)? Your project might be using the wrong interpreter
As the above suggests I'm trying to import a local module foo
It's just got a class inside it with a load of functions.
I've tried
import foo
and
from foo import *
and
import .foo
and
from .foo import *
and
from sub_directory_name.foo import *
etc.
I've set various directors to sub directories. I've appended my system path to include these sub folders and nothing works, they all just error on import.
Thanks in advance for any help.
EDIT : I usually use VS Code for JS, but I set it up for Python and it all works. So VS code is fine with importing a local module, Pycharm is not.
Foiled by my IDE.
Hello,
I want to use the system interpreter for my project because I need to use tkinter for matplotlib, but if I choose python3.8 as interpreter for my project I can't use modules I have installed globally (e.g. numpy or matplotlib).
However if I run my project in the terminal the modules are recognized and everything works fine.
I would love if someone either knows how to import tkinter in an virtual environment or how to configure the interpreter to use global packages.
Edit: I'm on Linux (Pop OS)