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

使用venv虚拟环境时Jupyter Notebook导入uproot包报ModuleNotFoundError

问题排查与解决建议

Hey Paul, I totally get how frustrating this is—when everything looks like it should work but Jupyter still throws that ModuleNotFoundError. Let's break this down step by step.

First, Verify the Jupyter Kernel's Python Path

The most common culprit here is that Jupyter is using a different Python kernel than your virtual environment, even though your terminal shows you're in the venv. Let's confirm this:

  1. In your Jupyter Notebook/Lab, run this code in a cell:
    import sys
    print(sys.executable)
    
  2. Compare this path to the one you get when you run which python in your activated venv terminal. If they don't match, that's exactly the problem—Jupyter is using a kernel tied to a different Python installation.

Fix: Add Your Virtual Environment as a Jupyter Kernel

To get Jupyter to recognize your venv's packages, you need to register the venv as a dedicated kernel:

  1. Go back to your terminal, make sure your venv is activated (. .my-venv/bin/activate on Linux/macOS, .my-venv\Scripts\activate on Windows).
  2. Install the ipykernel package in your venv (this lets Jupyter connect to your venv):
    pip install ipykernel
    
  3. Register your venv as a Jupyter kernel with a name you'll recognize:
    python -m ipykernel install --user --name=my-venv-kernel
    
    (You can replace my-venv-kernel with something like .my-venv to keep it consistent with your venv name.)
  4. Restart your Jupyter Notebook/Lab.
  5. In the top-right corner of your notebook, click the current kernel name (probably "Python 3") and select your new kernel (my-venv-kernel) from the list.
  6. Now try importing uproot again—it should work!

Double-Check Installation Path (Just to Be Safe)

If the kernel fix doesn't work, let's confirm uproot is installed in the right place:

Run this in a Jupyter cell:

!pip show uproot

Look at the Location field—it should point to your venv's lib/pythonX.X/site-packages folder. If it does, the kernel issue was definitely the problem. If not, there might have been a mix-up during installation, but since your CLI Python can import uproot, this is unlikely.

Quick Sanity Check: How You Started Jupyter

Make sure you launched Jupyter after activating your virtual environment. If you started Jupyter first and then activated the venv later, Jupyter won't pick up the venv's packages. Always activate the venv first, then run jupyter lab or jupyter notebook.

Hope this gets you up and running with uproot soon—being stuck on package imports when you need to work with data is the worst!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 19:42:52