PyCharm 模块名称冲突
我的包中有一个名为“io”的模块:mypackage.io。这会导致与Python内置io包发生冲突。因此,每当我使用 PyCharm 执行代码调试时,由于 pydev helper 使用 gzip (进而使用 io),我会遇到模块 ImportError。该问题部分是由于 PyCharm 自动将我的包路径添加到解释器路径中。所以我有两个选择
- 来自尝试导入与构建同名的模块的答案-in module 导致导入错误,看来我需要对 gzip.py 进行更改,以便它通过绝对导入来导入 io。
- 将我的模块从 io 重命名为 Something_else
我是否缺少更好的解决方案?
I have a module named 'io' in my package: mypackage.io. This causes a conflict with the Python built-in io package. Thus, whenever I use PyCharm to perform debugging of my code, since pydev helper uses gzip (which in turns uses io), I encounter a module ImportError. The problem is partly due to PyCharm automatically add my package path to the interpreter path. So I am left with two options
- From the answer of Trying to import module with the same name as a built-in module causes an import error, it seems that I need to make changes to gzip.py so that it will import io by absolute importing.
- Rename my module from io to something_else
Am I missing a better solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您基本上有两个选择:
一般而言,将自定义包映射到内置程序之上是不好的形式,除非您有意更改默认内置程序的行为。任何短期的游戏都会被许多长期的问题所抵消。
You basically have two options:
Generally speaking, its bad form to map a custom package atop a built-in unless you are intentionally changing that default builtin's behavior. Any short-term game will be offset by many, long-term headaches.