Can't import dgl (circular import error)

I am having trouble installing dgl (cpu version). I’ve tried with both pip and conda, but in both cases I get the error.

AttributeError: partially initialized module ‘dgl’ has no attribute ‘graph’ (most likely due to a circular import)

I’m using python 3.10 in a virtual environment. I have the cpu version of torch 2.2.1 installed.

Could someone help with this please?

what is your OS version? How do you install DGL? Did you uninstall previous versions of DGL beforehand?

Refer to Deep Graph Library for install command.

I’m running Fedora 39. I followed the instructions here: Deep Graph Library.

When I tried installing with pip I did

pip install  dgl -f
pip install  dglgo -f

And when that didn’t work I uninstalled them and tried
conda install -c dglteam dgl

Both times I got the same circular import error when importing dgl, but I did not see any errors during installation.

These are my system setup and I can import dgl.

dgl 2.1.0+cu121
dglgo 0.0.2
(.mvenvl) root@MSI:/home/second_trial/linevd# pip list | grep torch
pytorch-lightning 2.2.0.post0
torch 2.1.1+cu121
torch_geometric 2.5.1
torch-scatter 2.1.2
torch-tb-profiler 0.4.3
torchaudio 2.1.1+cu121
torchdata 0.7.1
torchinfo 1.8.0
torchmetrics 1.3.1
torchsummary 1.5.1
torchtext 0.17.0
torchvision 0.16.1+cu121
tsne-torch 1.0.1
(.mvenvl) root@MSI:/home/second_trial/linevd# python3
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import dgl
Traceback (most recent call last):
File “”, line 1, in
File “/home/second_trial/linevd/.mvenvl/lib/python3.11/site-packages/dgl/”, line 14, in
from .backend import backend_name, load_backend # usort: skip
File “/home/second_trial/linevd/.mvenvl/lib/python3.11/site-packages/dgl/backend/”, line 122, in
File “/home/second_trial/linevd/.mvenvl/lib/python3.11/site-packages/dgl/backend/”, line 51, in load_backend
from …_ffi.base import load_tensor_adapter # imports DGL C library
File “/home/second_trial/linevd/.mvenvl/lib/python3.11/site-packages/dgl/_ffi/”, line 50, in
_LIB, _LIB_NAME, _DIR_NAME = _load_lib()
File “/home/second_trial/linevd/.mvenvl/lib/python3.11/site-packages/dgl/_ffi/”, line 39, in _load_lib
lib = ctypes.CDLL(lib_path[0])
File “/usr/lib/python3.11/ctypes/”, line 376, in init
self._handle = _dlopen(self._name, mode)
OSError: cannot open shared object file: No such file or directory

Could you try to build from source on your platform by referring to Install and Setup — DGL 2.1.0 documentation ?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.