导入igraph时出现AttributeError如何解决?

发布于 2024-11-14 23:51:39 字数 1077 浏览 3 评论 0原文

当我在项目中导入 igraph 包时,出现 AttributeError。这种情况只发生在项目目录中:

[12:34][~]$ python2
Python 2.7.1 (r271:86832, Apr 15 2011, 12:09:10) 
[GCC 4.5.2 20110127 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import igraph
>>> 

[12:34][~]$ cd projectdir/
[12:34][projectdir]$ python2
Python 2.7.1 (r271:86832, Apr 15 2011, 12:09:10) 
[GCC 4.5.2 20110127 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import igraph
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/igraph/__init__.py", line 42, in <module>
    import gzip
  File "/usr/lib/python2.7/gzip.py", line 36, in <module>
    class GzipFile(io.BufferedIOBase):
AttributeError: 'module' object has no attribute 'BufferedIOBase'
>>>

项目目录中没有文件 igraph.py:

[12:34][projectdir]$ ls -alR | grep igraph | wc -l
0

并且没有循环导入。

我该如何解决这个错误?

When I import the igraph package in my project, I get an AttributeError. This only happens in the project directory:

[12:34][~]$ python2
Python 2.7.1 (r271:86832, Apr 15 2011, 12:09:10) 
[GCC 4.5.2 20110127 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import igraph
>>> 

[12:34][~]$ cd projectdir/
[12:34][projectdir]$ python2
Python 2.7.1 (r271:86832, Apr 15 2011, 12:09:10) 
[GCC 4.5.2 20110127 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import igraph
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/igraph/__init__.py", line 42, in <module>
    import gzip
  File "/usr/lib/python2.7/gzip.py", line 36, in <module>
    class GzipFile(io.BufferedIOBase):
AttributeError: 'module' object has no attribute 'BufferedIOBase'
>>>

There is no file igraph.py in the project directory:

[12:34][projectdir]$ ls -alR | grep igraph | wc -l
0

And there are no circular imports.

How can I solve this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

左耳近心 2024-11-21 23:51:39

最有可能的是,~/projectdir 或项目配置的路径之一中有一个模块 io。 igraph 导入的 gzip 模块以

import io

内置 io 模块开头,而不是您项目的模块。查找 io 目录,或 io.pyio.pyc。它还可以帮助检查 sys.path 中是否有可能包含名为 io 的模块的任何其他目录(可能在 ~/projectdir 之外)。

Most likely, there is a module io in ~/projectdir or one of the paths the project configures. The gzip module imported by igraph starts with

import io

and expect the built-in io module, not your project's one. Look for an io directory, or io.py or io.pyc. It can also help to scrutinize sys.path for any other directories (maybe outside of ~/projectdir) that might contain modules named io.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文