Pydev 显示未解析的导入,但脚本运行? [英] Pydev shows unresolved import, but script runs?

查看:56
本文介绍了Pydev 显示未解析的导入,但脚本运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PyDev.

I am using PyDev.

我正在尝试将我的项目类组织成包.

I am trying to organise my project classes into packages.

例如在一个文件夹中,我有一个模块位于/libraries/fund_price_library.py

e.g. In a folder I have a module at /libraries/fund_price_library.py

在我项目的另一个文件中,我尝试使用以下方法导入:

In another file in my project, I try to import using:

from libraries.fund_price_library import FundPriceLibrary as fpl

PyDev 用红色下划线FundPriceLibrary as fpl",并用以下错误标记:

PyDev underlines "FundPriceLibrary as fpl" in red, marking it with this error:

unresolved import fpl

但是,我的脚本运行良好,所以我相信我的导入是正确的.

However, my script works perfectly fine, so I believe that I am doing the import correctly.

我的项目中有很多类似的错误,而且看起来很乱.但是,我的 python 代码有效,所以我假设我导入正确.

I have lots of similar errors all over my project, and it looks messy. However, my python code works, so I assume I am importing correctly.

如何抑制这些错误?

推荐答案

This问题可能会解决您的问题.

在 pydev 项目的属性中,有一个名为PyDev - PYTHONPATH"的窗格,以及一个名为外部库"的子窗格.您可以使用该窗格将源文件夹(具有 init.py 的任何文件夹)添加到路径中.然后,您的项目代码将能够从这些源文件夹中导入模块.

In the properties for your pydev project, there's a pane called "PyDev - PYTHONPATH", with a sub-pane called "External Libraries". You can add source folders (any folder that has an init.py) to the path using that pane. Your project code will then be able to import modules from those source folders.

可能只是 PyDev 不知道在哪里可以找到这些文件.

It might just be that PyDev doesn't know where to find the files.

这篇关于Pydev 显示未解析的导入,但脚本运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆