Windows環境Jupyter Notebook無法訪問npm和node(暫未解決)

Gold_stein發表於2024-10-18

Windows環境Jupyter Notebook無法訪問npm和node

content

The issue may arise from using Node.js and npm through NVM (Node Version Manager), which installs them in user-specific directories. While this setup works, Jupyter Notebook or Conda might not correctly detect the npm and node binaries due to path resolution issues on Windows.

Troubleshooting Steps

  1. Check if the PATH is set correctly for npm and node:
    Your output shows:

    C:\Users\11543\AppData\Roaming\nvm\v20.18.0\npm
    C:\Users\11543\AppData\Roaming\nvm\v20.18.0\npm.cmd
    C:\Users\11543\AppData\Roaming\nvm\v20.18.0\node.exe
    

    Ensure these paths are correctly added to your Windows PATH:

    • Open Control Panel → System → Advanced system settings → Environment Variables.
    • Under User variables or System variables, find the Path variable and ensure the following paths are included:
      C:\Users\11543\AppData\Roaming\nvm\v20.18.0\
      C:\Users\11543\AppData\Roaming\nvm\
      
  2. Set npm and Node.js in Conda's environment:
    Conda may not recognize the Node.js installed by NVM. To ensure compatibility, try explicitly setting the paths within the Conda environment.

    • Activate your Conda environment:

      conda activate base  # Or your specific environment
      
    • Set the Node.js path manually for that session:

      set PATH=C:\Users\11543\AppData\Roaming\nvm\v20.18.0;%PATH%
      

    Alternatively, you can install Node.js via Conda to avoid the path conflict:

    conda install -c conda-forge nodejs
    
  3. Ensure npm works within Jupyter:
    Open a Jupyter notebook and try executing the following code to check if npm is correctly detected:

    !npm -v
    !node -v
    

    If it still fails, try starting Jupyter with a modified path:

    set PATH=C:\Users\11543\AppData\Roaming\nvm\v20.18.0;%PATH% && jupyter notebook
    
  4. Verify and Clean npm Configuration:
    Sometimes, npm misconfigures itself when installed via multiple sources. Run:

    npm config delete prefix
    npm cache clean --force
    
  5. Rebuild Jupyter Extensions (if applicable):
    If you're using JupyterLab extensions:

    jupyter lab build
    

Conclusion

The problem likely lies in Conda or Jupyter not detecting the npm installed through NVM due to path configuration issues. Adding the correct paths to your environment variables or installing Node.js via Conda should resolve the issue.

嘗試了以上方法,但是暫未解決該問題;無論是用pip還是conda安裝的版本,均面臨此問題;不過該問題目前暫未對日常使用造成影響,因為還未安裝任何擴充套件。

相關文章