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

MacOS下使用pip install --user安装plotly模块报错,求分步解决

Hey there, let's work through your Plotly installation problem step by step, since you're dealing with macOS High Sierra 10.13.3 and have both Python 2.7.10 (your default) and Python 3.6 installed. We'll start with fixing the Plotly install, then touch on switching your default Python version as a bonus.

Step 1: Update Your Pip Versions First

Old versions of pip can cause all sorts of installation errors, so let's make sure both your Python 2.7 and 3.6 pip tools are up to date:

  • For Python 2.7 (your current default):
    sudo pip install --upgrade pip
    
    You'll need to enter your macOS user password when prompted—this is normal for admin-level updates.
  • For Python 3.6:
    sudo pip3 install --upgrade pip
    
Step 2: Install Plotly for the Correct Python Version

Since your python command defaults to 2.7, the regular pip will install Plotly there. If you want it for Python 3.6, use pip3 instead:

  • Install for Python 2.7:
    pip install plotly
    
  • Install for Python 3.6:
    pip3 install plotly
    

Troubleshooting Common Errors

If you run into permission issues (no write access to system directories), skip the sudo and use the --user flag instead:

# For Python 2.7
pip install plotly --user

# For Python 3.6
pip3 install plotly --user

If you're hitting network timeouts or slow downloads, you can use a trusted PyPI mirror by appending -i [mirror URL] to the install command—just replace [mirror URL] with a reliable mirror address you prefer.

Step 3: Verify the Installation Worked

Let's confirm Plotly is installed correctly:

  • For Python 2.7:
    Open terminal, type python, then run these lines:
    import plotly
    print(plotly.__version__)
    
    If you see a version number (like 5.15.0) without errors, you're good to go.
  • For Python 3.6:
    Type python3 in terminal, then run the same code snippet above.
Bonus: Switch Default Python to 3.6

Since you mentioned wanting to fix this later, here's a safe way to make Python 3.6 your default when you type python:

  1. Open your shell profile file:
    • If you use Bash (default on High Sierra):
      open ~/.bash_profile
      
    • If you use Zsh (if you've switched):
      open ~/.zshrc
      
  2. Add this line at the bottom of the file (replace the path with the output of which python3 if yours is different):
    alias python="/usr/local/bin/python3"
    
  3. Save the file and close it, then apply the change immediately with:
    source ~/.bash_profile
    # Or source ~/.zshrc if you edited that file
    
  4. Test it by running python --version—it should now show Python 3.6.x.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 09:00:03