MacBook Yosemite系统下AWS CLI安装失败求助
Let's fix this installation issue step by step. The core problem here is a compatibility conflict between the outdated awscli-bundle script and your pip 19.1.1 version—pip changed how its main function is structured after version 10, which breaks the old bundle script's logic.
第一步:清理之前的安装残留
First, let's remove all leftover files from your previous attempts to avoid conflicts:
- Delete the AWS installation directory created by the bundle script:
sudo rm -rf /usr/local/aws - Delete the downloaded
awscli-bundlefolder:rm -rf ~/awscli-bundle - Check for any existing
awscommand and remove it if present:which aws && sudo rm $(which aws)
方法一:用pip3直接安装(推荐)
AWS now recommends using pip directly instead of the legacy bundle script, which will avoid the pip compatibility issue. Since you already have Python 3.7 and pip3 set up:
- Install AWS CLI to your user directory (no sudo needed, avoids permission problems):
pip3 install awscli --user - Add your user-specific Python bin directory to your PATH so the
awscommand is accessible globally. Edit your~/.bash_profile:echo 'export PATH="$HOME/Library/Python/3.7/bin:$PATH"' >> ~/.bash_profile - Refresh your shell environment to apply the PATH change:
source ~/.bash_profile - Verify the installation works:
aws --version
方法二:用虚拟环境隔离安装(如果方法一仍有问题)
If you run into permission or dependency conflicts with your system Python, use a virtual environment to isolate the AWS CLI installation:
- Install virtualenv to your user directory:
pip3 install virtualenv --user - Create a dedicated virtual environment for AWS CLI:
virtualenv -p python3.7 ~/aws-venv - Activate the virtual environment:
source ~/aws-venv/bin/activate - Install AWS CLI inside the virtual environment:
pip install awscli - Verify the installation:
aws --version - To use the
awscommand globally without activating the virtual environment, create a symbolic link:sudo ln -s ~/aws-venv/bin/aws /usr/local/bin/aws - You can exit the virtual environment anytime with:
deactivate
原报错原因分析
The error ImportError: cannot import name 'main' from 'pip' happens because:
- The
awscli-bundlescript uses an older version of virtualenv that expects the old pipmainimport pattern. - Your system's pip 19.1.1 uses a new structure where
from pip import mainis no longer valid (this changed in pip 10+). - The virtualenv created by the bundle script was incorrectly pulling in your user-level pip files instead of using its own isolated pip version.
内容的提问来源于stack exchange,提问作者umemon

