【macOS】【zsh报错】zsh: command not found: python

【macOS】【zsh Error】zsh: command not found: python

本地已经安装了Python,且能在Pycharm中编译Python程序并运行。

但是,在macOS终端,运行Python,报错。

首先要确认你在macOS系统下,是否安装了Python。

如果安装了,还要确认Python名称。

例如,我在终端输入python,报错:zsh: command not found: python。

而实际上,我的Python,安装在路径:/usr/local/bin

且文件名为:Python3.

所以,需要在终端输入:python3,才能正确运行。


下面是配置环境变量的步骤:


There are a few possible reasons why you might be getting this error:

1. Python is not in your PATH:

  • Check the installation location:

    Make sure you installed Python to a directory that is in your system's PATH.

    Common locations include /usr/local/bin or /opt/anaconda3/bin.

  • Add the directory to your PATH:

    If the directory is not in your PATH,

    you can add it by editing your .zshrc or .bash_profile file.

    For example,

    if Python is installed in /usr/local/bin,

    you would add the following line to your .zshrc file:

    Bash

    复制代码
    export PATH="/usr/local/bin:$PATH"

    【Note】:

    Goodmao has successfully completed the Python installation and configured the PATH environment variable.

    复制代码
    vi ~/.bash_profile
    /usr/local/bin 
  • Restart your terminal:

    After making changes to your .zshrc or .bash_profile file,

    you need to restart your terminal for the changes to take effect.

2. You're using the wrong shell:

  • Make sure you're using the correct shell.
    If you're using a different shell, such as bash,
    you might need to use a different command to start Python.
    For example, in bash, you would use python3 instead of python.

3. Python is not installed correctly:

  • If you're still having trouble, it's possible that Python is not installed correctly.
    Try reinstalling Python or checking the installation logs for any errors.

Here's a summary of the steps you can take to resolve the issue:

  1. Check the installation location:
    Make sure Python is installed in a directory that is in your PATH.
  2. Add the directory to your PATH:
    If necessary, add the directory to your .zshrc or .bash_profile file.
  3. Restart your terminal:
    Restart your terminal for the changes to take effect.
  4. Try using a different shell:
    If you're using a different shell, try using the appropriate command to start Python.
  5. Reinstall Python:
    If all else fails, try reinstalling Python.
相关推荐
许彰午3 分钟前
73_Python爬虫Scrapy框架入门
爬虫·python·scrapy
@realXuan9 分钟前
人工智能AI编程 Agent 入门系列教程之 Claude Code 是什么
人工智能·python·ai编程
孤狼warrior14 分钟前
从冒泡到传送带流水线:一个3D沉浸式算法靶场,让思想的伟力改变世界
python·算法·typescript
零点零一15 分钟前
QT 5升级到 Qt 6 使用 Clazy 检查将 C++ 应用程序移植到 Qt 6
开发语言·c++·qt
搬砖柯17 分钟前
系列11-测试平台 MCP Server 实践:用 Kimi Code 自然语言查项目、跑 API 回归
人工智能·python·ai·开源·自动化
向阳是我18 分钟前
在 Mac(M2)上用 faster-whisper 实现高精度中文语音转文字
python·macos·ai·whisper·语音识别
Tisfy19 分钟前
MacOS:首次外接键盘初始化设置(Option/Command互换、左上角·~而非§±)
macos·计算机外设
caimouse20 分钟前
reactos 测试安装32位微信失败的日志
开发语言·微信
山海云端有限公司22 分钟前
企业工商信息查询API实战:从认证到数据解析全流程
python·api·数据解析·企业信息查询·聚合api·第三方集成
爱奥尼欧24 分钟前
轻量级可扩展日志框架-异步日志与系统集成
开发语言·数据库·c++·学习