pylint 导入和动态路径修改 [英] pylint import and dynamic path modification

查看:56
本文介绍了pylint 导入和动态路径修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目结构通常是这样的:

My projects are generally structured like this:

projectname/
    __init__.py
    python/
        mymodule.py
    other_stuff/
    more_stuff/

其中 __init__.py 包含以下代码

import os
mypath = os.path.dirname(os.path.realpath(os.path.abspath(__file__)))
__path__ = [mypath, mypath+"/python"]

这在导入时跳过"python 目录以允许以 from projectname import mymodule 而不是 from projectname.python import mymodule 形式的 python 代码代码>.

This "skips" the python directory when importing to allow python code in the form from projectname import mymodule rather than from projectname.python import mymodule.

这似乎破坏了 pylint,尽管 $PYTHONPATH 设置正确,但无法导入项目中的任何模块.创建软链接 projectname ->projectname 中的 python 修复了一些问题,但不是一个合适的解决方案.

This appears to break pylint however, being unable to import any modules in the project despite $PYTHONPATH being set correctly. Creating a softlink projectname -> python in the projectname fixes things but isn't a suitable solution.

关于如何在不改变目录结构的情况下解决此问题的任何建议?

Any suggestions on how to fix this without altering the directory structure?

推荐答案

我觉得你有点卡住了.Pylint 不会处理您的 __init__.py 文件,因此除非您能找到另一种方式将该信息导入 pylint,否则我认为它不会起作用.祝你好运.

I think you're kind of stuck. Pylint doesn't process your __init__.py file so unless you can find another way of getting that information into pylint, I don't think it's going to work. Good luck.

这篇关于pylint 导入和动态路径修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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