0

I want to use the Algorithms inside of the cdlib library for network analysis. I installed cdlib by:

pip install cdlib

However I am unable to check the version of the same library using

cdlib --version

which gives me an error, saying:

zsh: command not found: cdlib

Moreover, upon using

from cdlib import algorithms

--------------------------------------------------------------------------- ImportError Traceback (most recent call last) /var/folders/gm/d0bzgb6n4k95px0_1x9hqq_h0000gn/T/ipykernel_43989/3546710294.py in ----> 1 from cdlib import algorithms 2 import networkx as nx

~/opt/anaconda3/lib/python3.9/site-packages/cdlib/algorithms/init.py in 1 from .edge_clustering import * ----> 2 from .crisp_partition import * 3 from .overlapping_partition import * 4 from .attribute_clustering import * 5 from .bipartite_clustering import *

~/opt/anaconda3/lib/python3.9/site-packages/cdlib/algorithms/crisp_partition.py in 52 53 try: ---> 54 import infomap as imp 55 except ModuleNotFoundError: 56 missing_packages.add("infomap")

~/opt/anaconda3/lib/python3.9/site-packages/infomap.py in 36 from . import _infomap 37 else: ---> 38 import _infomap 39 40 try:

ImportError: dlopen(/Users/hrisod/opt/anaconda3/lib/python3.9/site-packages/_infomap.cpython-39-darwin.so, 0x0002): Library not loaded: /usr/local/opt/llvm/lib/libomp.dylib
Referenced from: /Users/hrisod/opt/anaconda3/lib/python3.9/site-packages/_infomap.cpython-39-darwin.so Reason: tried: '/usr/local/opt/llvm/lib/libomp.dylib' (no such file), '/usr/local/lib/libomp.dylib' (no such file), '/usr/lib/libomp.dylib' (no such file)

This error is found. I tried reinstalling the same library even using the ways in the documentation, all too no avail. I am using jupyter notebook on mac for this project. Can someone please help me find out how to properly download the library.

  • What you installed via `pip install cdlib` is a Python library, and not a command line executable . And so running `cdlib --version` on the command line would not be expected to work. You are confusing concepts there. The fact you don't get something like a `ModuleNotFoundError` when you try `from cdlib import algorithms` means the installation happened. You can check the version by running `!pip freeze | grep cdlib` in your notebook. (Based on [here](https://stackoverflow.com/a/20180597/8508004).) Note, only use the exclamation point because not installing from in notebook in that case, ... – Wayne Dec 16 '22 at 19:27
  • use `%pip install ` when trying to install using `pip` in a cell in a notebook. See my comment [here](https://stackoverflow.com/questions/74770639/modulenotfounderror-in-python#comment131969319_74770639) for more about the modern magic command and the comment right below for why use of the exclamation point in conjunction with `pip install` is no longer best practice. – Wayne Dec 16 '22 at 19:30
  • The question I was linking to in my comment above, got deleted. Here's the information: `%pip install ` is the current best practice, see [here](https://discourse.jupyter.org/t/why-users-can-install-modules-from-pip-but-not-from-conda/10722/4?u=fomightez) about the modern magic commands that insure that the installation occurs in the environment backing the notebook. Use of an exclamation point alone doesn't do this, more on that at the top [here](https://discourse.jupyter.org/t/location-of-libraries-or-extensions-installed-in-jupyterlab/16303/2?u=fomightez). – Wayne Dec 19 '22 at 16:59

1 Answers1

0

Reading your error more thoroughly, you'll note that it says 54 import infomap as imp 55 except ModuleNotFoundError: 56 missing_packages.add("infomap"). (Seems to relate to this. this bug report, and here. Since you are on a Mac, is this pertnent ==> here?)

I note you are using conda but trying to install cldlib with pip. This says maybe trying strictly with cdlib from conda may help. Uninstall via pip maybe first, using python -m pip uninstall cdlib, before trying conda.

If you want to try dealing with the infomap stuff first though ...
Since you are using conda, you should try using Anaconda that to install infomap. If you just care about using it in this notebook, you can try that with %conda install -c conda-forge infomap in a cell in the notebook.

Wayne
  • 6,607
  • 8
  • 36
  • 93