You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code中Jupyter虚拟环境内核导入pgmpy失败,终端却成功

pgmpy 1.0.0 导入DiscreteBayesianNetwork失败排查

问题场景

在Windows系统的VS Code Jupyter Notebook中执行以下代码:

from pgmpy.models import DiscreteBayesianNetwork

触发导入错误:

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

当前已安装pgmpy 1.0.0最新版本,完整依赖包版本如下:

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

矛盾现象

在终端中执行Python命令行,导入操作可成功完成,且验证版本无误:

$ 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'

补充信息

  • 项目及虚拟环境(venv)存储在Google Drive中
  • 使用Git Bash终端时,VS Code已激活虚拟环境,但执行which python返回全局Python路径而非虚拟环境内的路径:
$ source "x:/My Drive/.venv/Scripts/activate"
(.venv) 
$ which python
/c/Users/user/AppData/Local/Programs/Python/Python313/python

内容的提问来源于stack exchange,提问作者heretoinfinity

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 05:19:51