dan479
dan479

Reputation: 43

"No Module named..."-error in editor despite code appearing to work

I've been struggling for quite some time trying to import a module from a molder in a separate directory on my computer for a python project. Currently the code seems to work, but Pycharm is still giving me errors that the module cannot be found. Despite this, if I run the code it seems to do what is intended.

What I have is essentially this:

import sys
sys.path.append(r'D:\Progam\bin')
import foo

Where foo is a module found in D:\Progam\bin, and it's warning me that there is no module named foo. Considering how much issue I've for some reason had to get this working I'm hesitant to just ignore the warning if there's some underlying problem

Anyone have any idea what's happening here?

Upvotes: 1

Views: 314

Answers (1)

ebdm
ebdm

Reputation: 15

Because the file isn't in your path globally, your IDE isn't recognizing that it is then valid during execution. It would probably be a security issue if it were adding files to its path from potentially unknown code.

You could either add that directory to your path via CMD like so:

set PATH=%PATH%;C:\your\path\here\

Or just ignore the error.

EDIT: Ignore that, I'm being a sleep deprived dumbass. Take a look at:

how to manage sys.path globally in pycharm

(Thought this edit would be slightly more useful than me just deleting my answer)

Upvotes: 1

Related Questions