安装Hyperledger Composer开发工具报错:找不到Python2.7.9可执行文件
Hey there, let's tackle that frustrating gyp ERR! configure error you're seeing when running npm install -g composer-cli. The root issue is that node-gyp (a tool npm uses to build native modules) requires Python 2.7.x (not Python 3.x), and it's specifically looking for version 2.7.9—though most 2.7.x releases will work just fine. Here's how to fix it:
Option 1: If You Already Have Python 2.7 Installed
First, confirm where your Python 2.7 is located by running this in your terminal:
which python2.7
This will output a path like /usr/bin/python2.7 or /usr/local/bin/python2.7.
Temporary Fix (Only for Current Terminal Session)
Set the PYTHON environment variable temporarily, then run the install command again:
export PYTHON=/path/to/your/python2.7 npm install -g composer-cli
Replace /path/to/your/python2.7 with the actual path from the which command.
Permanent Fix (Applies to All Future Terminal Sessions)
Add the environment variable to your shell config file so you don't have to set it every time:
- If you use Bash:
- Open your
~/.bash_profileor~/.bashrcfile in a text editor. - Add this line (replace the path with your actual Python 2.7 path):
export PYTHON=/usr/bin/python2.7 - Save the file and run
source ~/.bash_profile(orsource ~/.bashrc) to apply the changes.
- Open your
- If you use Zsh:
- Open your
~/.zshrcfile in a text editor. - Add the same
export PYTHON=...line as above. - Save and run
source ~/.zshrcto apply.
- Open your
Option 2: If You Don't Have Python 2.7 Installed
On macOS
- Use Homebrew to install Python 2.7 (if you have Homebrew installed):
After installation, the path will typically bebrew install python@2/usr/local/bin/python2.7—use this path in the steps from Option 1. - Alternatively, download the official Python 2.7 installer (grab the latest 2.7.x release, like 2.7.18), install it, then find its installation path (usually
/usr/bin/python2.7).
Quick Alternative: Specify Python Directly in the npm Command
You can also skip setting environment variables entirely by passing the Python path directly to npm:
npm install -g composer-cli --python=/path/to/your/python2.7
Bonus: Fix Additional node-gyp Dependencies
If you run into further errors after fixing the Python issue, node-gyp might also need build tools like make or gcc. On macOS, install the Xcode Command Line Tools with:
xcode-select --install
Give these steps a go, and you should be able to get the Hyperledger Composer CLI installed without hitting that Python error!
内容的提问来源于stack exchange,提问作者Vikas Banage

