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

Windows 10 CMD中Python及命令失效,matplotlib安装遇阻求助

Troubleshooting Matplotlib Installation on Windows 10

Hey there, let's work through this matplotlib installation issue step by step—sounds like you're hitting a common PATH/environment variable snag on Windows 10. Here's what to try:

Step 1: Verify Python & Pip Are Properly Added to System PATH

First, a critical note: always open a new Command Prompt window after making changes to environment variables—existing terminals won't pick up the updates automatically.

Run these commands one by one to check if Python and pip are recognized:

  • python --version
  • py --version
  • pip --version

If any of these throw a "not recognized" error, double-check your environment variables:

  1. Right-click This PC > Properties > Advanced system settings
  2. Click Environment Variables
  3. Under System Variables, find the Path entry and click Edit
  4. Ensure you have two key entries:
    • The main Python installation folder (e.g., C:\Python311)
    • The Scripts subfolder inside your Python directory (e.g., C:\Python311\Scripts)—this is where pip is stored
  5. Save all changes, then restart your Command Prompt and test the commands again.

Step 2: Fix the Pip Update Failure

If py -m pip install -U pip is throwing exceptions, try these workarounds:

  • Use the full Python executable path: If you know where Python is installed (e.g., C:\Python311\python.exe), run this command directly:
    C:\Python311\python.exe -m pip install -U pip
    
  • Reinstall pip from scratch:
    1. Open Notepad, paste the official get-pip.py code into a new file, and save it as get-pip.py on your desktop.
    2. Open Command Prompt, navigate to your desktop with: cd C:\Users\YourUsername\Desktop (replace YourUsername with your actual Windows username)
    3. Run: py get-pip.py (or python get-pip.py if that command works for you) to reinstall pip fresh.

Step 3: Install Matplotlib

Once pip is working correctly, install matplotlib with one of these commands:

  • py -m pip install matplotlib
  • If you confirmed pip is in your PATH, you can also use: pip install matplotlib
  • If you run into permission errors, add the --user flag to install it for your user account only (avoids needing admin rights):
    py -m pip install --user matplotlib
    

Quick Confirmation Test

After installation, run this command in Command Prompt to make sure everything works:

py -c "import matplotlib.pyplot as plt; plt.plot([1,2,3]); plt.savefig('test_plot.png'); print('Matplotlib installed successfully!')"

If you see the success message and a test_plot.png file appears in your current folder, you're all set to start plotting your data.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 10:26:58