Mac系统Python 2.7环境下无法安装TensorFlow求助
Let's break down what went wrong first:
- You're working in a Python 2.7 Virtualenv, but you used
pip3(which targets your system's Python 3.7) to install a Python 3-specific TensorFlow wheel. This mismatch is causing the grpcio installation failure—since TensorFlow 1.8.0 relies on an older grpcio version that doesn't play nicely with Python 3.7.
Here's how to fix it step by step:
Re-activate your Python 2.7 Virtualenv
Make sure you're in the correct isolated environment first. Replaceyour_virtualenv_folderwith the actual name/path of your Virtualenv directory:source your_virtualenv_folder/bin/activateVerify you're on Python 2.7 by running:
python --versionIt should output something like
Python 2.7.x.Upgrade pip to the required version (≥8.1)
Use the environment's nativepip(notpip3) to upgrade pip itself:pip install --upgrade pipInstall the correct TensorFlow wheel for Python 2.7
You were using the Python 3 wheel before—switch to the Python 2.7-specific one, and usepip(notpip3) to run the install:pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.8.0-py2-none-any.whlTroubleshoot grpcio installation (if needed)
If you still hit grpcio-related errors, install a compatible version of grpcio first (TensorFlow 1.8.0 works well with grpcio 1.10.0):pip install grpcio==1.10.0Then re-run the TensorFlow install command from step 3.
Pro tip: Always double-check which pip/python you're using by running pip --version—it should show the path pointing to your Virtualenv folder, not the system's Python 3.7 directory.
内容的提问来源于stack exchange,提问作者Hansel Wahjono

