How to solve AttributeError when importing igraph? - python

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?

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.

Related

ImportError: libc10.so: cannot open shared object file: No such file or directory

While running smdataparallel, I see following error
# python
Python 3.6.10 |Anaconda, Inc.| (default, May 8 2020, 02:54:21)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import smdistributed.dataparallel.torch.distributed as dist
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/conda/lib/python3.6/site-packages/smdistributed/dataparallel/__init__.py", line 16, in <module>
import smddpcommon as hc
ImportError: libc10.so: cannot open shared object file: No such file or directory
libc10.so is made available by pytorch. Hence first
import torch
and then import packages that depend on pytorch.
You can use find to locate this file. For example, find YOUR_HOME_PATH -name "*libc10.so*". For example, I found /MY_HOME_PATH/anaconda3/envs/xrnerf/lib/python3.7/site-packages/torch/lib/libc10.so in mine.

multiprocessing_on_dill results in ModuleNotFoundError "__builtin__"

To overcome the limitations of pickle, I switched to multiprocessing_on_dill.
This started to generate an error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 107, in spawn_main
exitcode = _main(fd)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 117, in _main
self = reduction.pickle.load(from_parent)
ModuleNotFoundError: No module named '__builtin__'
Is there a way to overcome it?
Surprisingly, it still references C:\ProgramData\Anaconda3\lib\multiprocessing\.
While multiprocessing_on_dill has its own folder C:\ProgramData\Anaconda3\Lib\site-packages\multiprocessing_on_dill with the same set of files.
I'd suggest you use multiprocess instead of multiprocessing_on_dill... the former is better supported, and maintained by the dill author (me). It looks like multiprocess_on_dill is looking for __builtin__, which is where the builtin functions lived in python 2... in python 3, they are in builtins
>$ python
Python 2.7.16 (default, Apr 1 2019, 14:50:56)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import __builtin__
>>>
>$ python
Python 3.6.8 (default, Dec 30 2018, 13:04:41)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import __builtin__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named '__builtin__'
>>> import builtins
>>>
So, I think it's either you are running python 3, and using the python 2 version of the code -- or the module doesn't fully support python 3.

Python failing in sub directory, but working in home directory

I have an Ubuntu machine (18.04) on a VM. When I run python in the home directory, everthing responds normally, however when I run from a sub directory it is failing to import modules in the standard library.
The sequence below illustrates the problem
anon#anon-VirtualBox:~$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>import os
>>> os.environ['PATH']
'/bin:/home/anon/anaconda2/bin:/home/anon/bin:/home/anon/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'
>>> import logging
>>> exit()
Which is the expected behaviour.
However when I go into a subdirectory, the same operation fails
anon#anon-VirtualBox:~$ cd GitHub/bikeano
anon#anon-VirtualBox:~/GitHub/bikeano$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['PATH']
'/bin:/home/anon/anaconda2/bin:/home/anon/bin:/home/anon/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'
>>> import logging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "logging.py", line 5, in <module>
import logging.handlers
ImportError: No module named handlers
>>>
I do not understand what is happening here. Are there other environment variables which could affect this?
Also, this is occuring on a Virtualbox VM, and the same .vdi works normally on another machine? The host is Windows 10 on both machines.

Python module import fails when in file but from interpreter works

I have a module that I am unable to import from the import statement in the top of a file, but the same import works fine in the same interpreter.
Any thoughts on this?
➜ ~ python /home/barrett/Git/bnr_robot_software/src/bnr_robot_cloud /bnr_robot_cloud_common/src/bnr_robot_cloud_common/my_unique_script_name.py
Traceback (most recent call last):
File "/home/barrett/Git/bnr_robot_software/src/bnr_robot_cloud/bnr_robot_cloud_common/src/bnr_robot_cloud_common/my_unique_script_name.py", line 1, in <module>
from azure.servicebus import ServiceBusService
ImportError: No module named servicebus
➜ ~ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from azure.servicebus import ServiceBusService
>>>

Issue importing Python tempfile module

I am trying to create tempfile but my python versions do not allow me to proceed and give the following complaints.
Do I need to upgrade this version to use tempfile module.
Thanks
Python 2.4.3 (#1, Jan 9 2013, 06:47:03) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "tempfile.py", line 2, in ?
temp = tempfile.NamedTemporaryFile()
AttributeError: 'module' object has no attribute 'NamedTemporaryFile'
You are importing a local file. You have a file named tempfile.py in your local directory that masks the global module. import tempfile imports that file, not the standard library module.
Use print tempfile.__file__ to locate that file if you cannot find it. Rename that file to something else.
The Python 2.4 tempfile module supports NamedTemporaryFile without upgrading.

Categories

Resources