[Python] Failed import in jupyter notebook venv kernel in VS Code but successful import in...

Discussão em 'Python' iniciado por Stack, Maio 7, 2025.

  1. Stack

    Stack Membro Participativo

    I was trying to go over this pgymy tutorial and I ran into an issue with the package. I am running this on a Jupyter notebook on VS Code on Windows.

    from pgmpy.models import DiscreteBayesianNetwork


    However, I get this error:

    ImportError: cannot import name 'DiscreteBayesianNetwork' from 'pgmpy.models' (J:\.venv\Lib\site-packages\pgmpy\models\__init__.py)


    I see that I have version 1.0.0, which is the latest for pgmpy but here are the versions of the rest of the packages.

    $ pip list
    Package Version
    ----------------- -----------
    asttokens 3.0.0
    colorama 0.4.6
    comm 0.2.2
    debugpy 1.8.12
    decorator 5.1.1
    executing 2.2.0
    filelock 3.17.0
    fsspec 2025.2.0
    ipykernel 6.29.5
    ipython 8.32.0
    jedi 0.19.2
    Jinja2 3.1.5
    joblib 1.5.0
    jupyter_client 8.6.3
    jupyter_core 5.7.2
    MarkupSafe 3.0.2
    matplotlib-inline 0.1.7
    mpmath 1.3.0
    nest-asyncio 1.6.0
    networkx 3.4.2
    numpy 2.2.3
    opt_einsum 3.4.0
    packaging 24.2
    pandas 2.2.3
    parso 0.8.4
    patsy 1.0.1
    pgmpy 1.0.0
    pillow 11.1.0
    pip 25.0.1
    platformdirs 4.3.6
    prompt_toolkit 3.0.50
    psutil 6.1.1
    pure_eval 0.2.3
    Pygments 2.19.1
    pyro-api 0.1.2
    pyro-ppl 1.9.1
    python-dateutil 2.9.0.post0
    pytz 2025.2
    pywin32 308
    pyzmq 26.2.1
    scikit-learn 1.6.1
    scipy 1.15.2
    setuptools 75.8.2
    six 1.17.0
    stack-data 0.6.3
    statsmodels 0.14.4
    sympy 1.13.1
    threadpoolctl 3.6.0
    torch 2.6.0
    torchvision 0.21.0
    tornado 6.4.2
    tqdm 4.67.1
    traitlets 5.14.3
    typing_extensions 4.12.2
    tzdata 2025.2
    wcwidth 0.2.13


    The other thing I did was I ran python in the shell and the import worked and I also ran this answer's suggestion to check the module's version.

    $ python
    Python 3.13.1 (tags/v3.13.1:0671451, Dec 3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from pgmpy.models import DiscreteBayesianNetwork

    >>> from importlib.metadata import version
    >>> version('pgmpy')
    '1.0.0'


    Everything seems to check out. Is there something I am missing?

    Continue reading...

Compartilhe esta Página