Got Stuck Installing Klayr Commander on the Mac?
Installing klayr-commander
on a Mac with an M1 or M2 chip can be a journey full of unexpected errors and dependencies. After a long battle with npm
, yarn
, node-gyp
, and even distutils
, I've compiled a guide to help you skip the hassle. Follow these steps, and hopefully, you'll be up and running in no time!
1. Setting Up Node and Python
Make sure you’re using Node v18 or the latest version and have the right Python versions set up:
Install NVM (Node Version Manager) and then Node v18:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
nvm install 18
nvm use 18
Next, install pyenv to manage Python versions, as both Python 3.13 and 2.7 are often needed.
brew install pyenv
eval "$(pyenv init -)"
pyenv install 3.13
pyenv install 2.7
pyenv global 3.13 2.7
2. Additional Dependencies for Compatibility
You’ll need some extra tools for compatibility with Mac:
brew install autoconf automake libtool
3. Handling the "ModuleNotFoundError: No module named 'distutils'" Error
Sometimes, you might see an error like this:
ModuleNotFoundError: No module named 'distutils'
This usually happens when Python’s distutils
the package is missing, which is essential for building some modules. Here’s how to fix it:
Install setuptools
to include distutils
:
python3 -m pip install --upgrade setuptools
Verify that Python is accessible to node-gyp
. Check your Python path with:
which python3
Ensure distutils
is installed by upgrading Python’s built-in tools:
python3 -m ensurepip --upgrade
4. Install Klayr Commander
Now, install klayr-commander
using Yarn:
yarn global add klayr-commander
If you get a zeromq
error, you might need to install cmake
:
Reinstall zeromq
: After removing zeromq
, try reinstalling it with Yarn to get a fresh setup:
yarn global add zeromq
Rebuild node-gyp
: If needed, you can manually trigger a rebuild after reinstalling
node-gyp rebuild
- This should help remove and reinstall
zeromq
without relying onyarn global remove
.
brew install cmake
npm install -g node-gyp
npm cache clean --force
5. Fixing the "Error Importing BLST Native Bindings: 404 Not Found"
When installing klayr-commander
, you might encounter this error:
Error importing BLST native bindings: 404 Not Found
This is usually due to a missing Python executable or @chainsafe/blst
package issues. Here’s how to resolve it:
Ensure Python Is Available as
python
: Ifpython3
is installed, link it aspython
:sudo ln -s $(which python3) /usr/local/bin/python
Reinstall
@chainsafe/blst
:yarn global remove @chainsafe/blst yarn cache clean yarn global add @chainsafe/blst
Install Node.js Build Tools: Make sure Xcode command-line tools are installed.
xcode-select --install
yarn global add klayr-commander
again!
6. Updating Your PATH Variable
After installation, check if the klayr
command works:
klayr --version
If you get:
zsh: command not found: klayr
This just means the system can’t find klayr
. Add Yarn’s global binaries to your PATH
:
yarn global bin
Add this path to your .zshrc
(or .bashrc
if you use bash):
nano ~/.zshrc
Then add:
export PATH="$PATH:$(yarn global bin)"
Apply the changes:
source ~/.zshrc
7. Final Check
Run:
klayr --version
If you see the version number, congratulations! You’re all set. 🎉
Subscribe to my newsletter
Read articles from Adefisayo Adejumo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Adefisayo Adejumo
Adefisayo Adejumo
Software engineer with over two years of experience in delivering clean, readable and maintainable code with an unrelenting appetite for lifelong learning and development. Creative problem solver with a good grasp of object-oriented programming concepts, asynchronous programming, web development, REST APIs, microservices, data structures and algorithms, with outstanding communication, collaborative and team-building skills.