Select Page

Troubleshooting Guide: Resolving “zsh: command not found: py” Error

by | Jun 24, 2023

Zsh, or Z Shell, is a powerful and customizable shell that offers a range of features and enhancements over the default shells found in many operating systems. However, it’s not uncommon to encounter command not found errors while using Zsh, such as the “zsh: command not found: py” message.

This error typically occurs when Zsh cannot locate the Python executable. In this blog post, we will explore various troubleshooting steps to fix the “zsh: command not found: py” error and get your Python commands up and running in no time.

Check Python Installation:

The first step is to ensure that Python is installed on your system. Open a terminal and enter the following command:

python --version

If you receive an error message or if the Python version is not displayed, it means Python is not installed or not properly configured. In such cases, install Python from the official website or through a package manager like Homebrew (for macOS) or apt-get (for Ubuntu).

Verify Python Path

Sometimes, the “zsh: command not found: py” error occurs due to an incorrect or missing Python path configuration. Check the environment variables by running the following command:

echo $PATH

Ensure that the path to the Python executable is included in the output. The typical path for Python installations is /usr/local/bin or /usr/bin.

Update Shell Profile

If you have recently installed Python or made changes to your system configuration, it’s possible that your shell profile needs updating.

The shell profile file could be either .bash_profile, .bashrc, .zshrc, or a similar file depending on your system. Open the appropriate file in a text editor and add the following line:

export PATH="/usr/local/bin:$PATH"

Save the changes and restart your terminal or execute the following command for the changes to take effect:

source ~/.zshrc

Utilize Virtual Environments

To avoid conflicts between different Python versions or packages, it’s a good practice to use virtual environments. If you’re working on a project, create a new virtual environment using a tool like venv or conda:
python -m venv myenv

Activate the virtual environment with:

source myenv/bin/activate

Now try running Python commands within the activated virtual environment.

Reinstall Zsh

In some cases, the “zsh: command not found: py” error could be related to a Zsh installation issue. You can reinstall Zsh using a package manager or by downloading the latest version from the official website.

This process may vary depending on your operating system, so refer to the relevant documentation.

Verify Zsh Configuration

If none of the above steps work, it’s possible that your Zsh configuration is causing the issue. Check your .zshrc file or any other relevant configuration files for any conflicting settings or aliases related to Python.

Comment out or remove any lines that may interfere with the Python command execution.


Encountering the “zsh: command not found: py” error can be frustrating, but by following the troubleshooting steps outlined in this blog post, you should be able to resolve the issue and regain control over your Python commands within Zsh.

Remember to check your Python installation, verify the Python path, update your shell profile, consider using virtual environments, and if necessary, reinstall Zsh. With these steps, you’ll be back to running Python smoothly in no time.


Submit a Comment

Your email address will not be published. Required fields are marked *

Looking For Something?

Follow Us

Related Articles



When you use the HTTP/2 Network Protocol, websites load faster. But sometimes, you might see an error called err_http2_protocol_error, which stops you from opening some web pages. The good news is there are ways to fix this error. Whether you do it in your web browser...

Solving CORS Errors in React: A Step-by-Step Guide

Solving CORS Errors in React: A Step-by-Step Guide

What is Cross-Origin Resource Sharing (CORS)? The Concept Cross-Origin Resource Sharing, commonly known as CORS, is a security feature implemented by web browsers. Its primary function is to control web page requests made by scripts running on one domain to another...

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!