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

VS Code中Jupyter输出与本地终端不一致问题求助

VS Code中Jupyter输出与本地终端不一致问题求助

Hey there! I totally get why this is frustrating—you’ve got !nvcc -V working fine in your regular terminal but not in VS Code’s Jupyter notebook, and even reinstalling environments hasn’t helped. Let’s break down the most common reasons and fixes for this:

  • Your Jupyter notebook is using a different environment than your terminal
    Chances are, you’re activating a specific conda/virtualenv environment in your terminal (like conda activate my_cuda_env) but VS Code’s Jupyter is defaulting to a different kernel. Check the bottom-right corner of VS Code—you’ll see the current Jupyter kernel listed. Click it, then select the same environment you’re using in your terminal. That should sync up the tools available to Jupyter.

  • The PATH environment variable doesn’t include nvcc’s location in Jupyter
    Your terminal’s PATH has the folder where nvcc lives (usually something like /usr/local/cuda/bin or the bin folder of your CUDA installation), but Jupyter’s environment doesn’t inherit that path. Here’s a quick test:

    1. In your terminal, run which nvcc to get the full path to the executable (e.g., /usr/local/cuda/bin/nvcc).
    2. In your Jupyter notebook, run this code to add the path temporarily:
      import os
      # Replace the path below with the folder you got from `which nvcc` (strip off "/nvcc")
      os.environ['PATH'] += ':/usr/local/cuda/bin'
      
    3. Now try !nvcc -V again. If this works, you can make the change permanent by adding the path to your system’s environment variables, or by configuring VS Code’s Jupyter settings to include it.
  • VS Code isn’t inheriting your terminal’s environment variables
    On Linux or macOS, if you launch VS Code from the graphical interface (like your dock or applications folder), it might not load your shell’s configuration files (.bashrc, .zshrc, etc.) where you set up CUDA paths. Try closing VS Code, then opening it directly from your terminal with the code . command—this way, VS Code will inherit all the environment variables from your terminal session, including the ones for CUDA.

  • Jupyter kernel configuration is missing the path
    If none of the above works, you can check your Jupyter kernel’s config. Run jupyter kernelspec list in your terminal to find the path to your kernel’s folder. Inside that folder, edit the kernel.json file and add the PATH variable to the env section, like this:

    {
      "argv": ["python", "-m", "ipykernel_launcher", "-f", "{connection_file}"],
      "display_name": "My CUDA Env",
      "language": "python",
      "env": {
        "PATH": "/usr/local/cuda/bin:$PATH"
      }
    }
    

    Save the file, restart Jupyter in VS Code, and try again.

Reinstalling environments won’t fix this because the issue isn’t with the environment itself—it’s about how VS Code and Jupyter are loading that environment’s paths. Give these steps a shot, and you should get nvcc working in your notebook!

备注:内容来源于stack exchange,提问作者Yufan Andrew Liu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.21 12:58:11