简体   繁体   English

“No Module named...”-尽管代码似乎可以工作,但编辑器中仍出现错误

[英]"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.我一直在努力尝试从我计算机上单独目录中的成型机导入模块以用于 python 项目。 Currently the code seems to work, but Pycharm is still giving me errors that the module cannot be found.目前代码似乎可以工作,但 Pycharm 仍然给我错误,说找不到模块。 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.其中 foo 是 D:\\Progam\\bin 中的一个模块,它警告我没有名为 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?有人知道这里发生了什么吗?

Because the file isn't in your path globally, your IDE isn't recognizing that it is then valid during execution.由于该文件不在您的全局路径中,因此您的 IDE 无法识别它在执行期间是否有效。 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:您可以通过 CMD 将该目录添加到您的路径中,如下所示:

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 如何在pycharm中全局管理sys.path

(Thought this edit would be slightly more useful than me just deleting my answer) (认为​​这个编辑会比我只是删除我的答案稍微有用)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM