为什么 pylint 找不到这个包的模块? [英] Why is pylint unable to find this package's module(s)?

查看:148
本文介绍了为什么 pylint 找不到这个包的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 pylint,当我对单个文件进行 lint 时出现错误(如下所示).我正在使用 azure sdk,但这只是我所引用的包,在这里应该不重要.

I'm currently working with pylint, and I'm getting an error when I lint the single file (repro below). I'm using the azure sdk, but that is just the package I'm referencing, that shouldn't be significant here.

$ mkdir pylinttesting && cd pylinttesting
$ python3 -m venv venv
$ . venv/bin/activate
$ pip3 install azure==2.0.0rc6
$ echo 'from azure import mgmt' > app.py

运行此脚本文件不会导致任何问题 (python3 app.py)

Running this script file causes no issues (python3 app.py)

即使这是完全有效的并且运行/导入没有错误,pylint 仍然抱怨它.下面的相关输出(为了简洁而减少)...

Even though this is totally valid and runs/imports without error, pylint still complains about it. Relevant output below (cut down for brevity)...

E:  1, 0: No name 'mgmt' in module 'azure' (no-name-in-module)

External dependencies
---------------------
::

    azure (app)

但是!如果我运行这个小片段(在同一个虚拟环境中)...

But! If I run this little snippet (in the same virtual environment)...

import os
import pkgutil
import azure

package_path = os.path.dirname(azure.__file__)
[print(name) for _, name, _ in pkgutil.iter_modules([package_path])]

...我得到以下输出...

... I get the following output...

batch
common
mgmt
servicebus
servicemanagement
storage

显然 mgmt 模块位于 azure 包中.但我想知道为什么 pylint 不接受它?

So obviously the mgmt module lives in the azure package. But I'm wondering why pylint doesn't pick that up?

还值得注意的是,如果我执行 from azure import common(common 是包中的另一个模块),pylint 不会抛出错误.

It's also worth noting that if I do from azure import common (common is another module in the package), pylint doesn't throw the error.

有没有想过为什么 pylint 可能对包中的这个 mgmt 模块不满意?

Any thoughts on why pylint may be unhappy with this mgmt module in the package?

编辑:pylint 版本信息...

EDIT: pylint version information...

pylint 1.6.5, 
astroid 1.4.9
Python 3.6.0 (default, Dec 24 2016, 00:01:50) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]

推荐答案

您使用的 Pylint 版本(尚)不支持 declare_namespace 用于创建命名空间.你用的pylint/astroid是什么版本的?

You are using Pylint version that does not (yet) support declare_namespace for creating namespaces. What are the version of pylint/astroid used by you?

参见 https://github.com/PyCQA/pylint/issues/687 用于类似问题和链接到支持此命名空间创建的代码.

See https://github.com/PyCQA/pylint/issues/687 for similar issue and link to code which supports this namespace creation.

请记住,Pylint 在分析过程中实际上并不运行 Python 代码,因此必须通过编写自定义代码来支持大多数非标准(不可推断)构造.

Keep in mind that Pylint actually does not run Python code during analysis, so most of non-standard (non-inferable) constructs have to be supported by writing custom code.

这篇关于为什么 pylint 找不到这个包的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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