【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.
相关推荐
2401_873544924 分钟前
使用Python处理计算机图形学(PIL/Pillow)
jvm·数据库·python
njidf9 分钟前
自动化机器学习(AutoML)库TPOT使用指南
jvm·数据库·python
只与明月听10 分钟前
RAG深入学习之向量数据库
前端·人工智能·python
froginwe1115 分钟前
Bootstrap4 折叠组件使用指南
开发语言
sunwenjian88616 分钟前
SpringBean的生命周期
java·开发语言
毕设源码-赖学姐37 分钟前
【开题答辩全过程】以 基于Java的游泳馆会员管理系统的设计与实现为例,包含答辩的问题和答案
java·开发语言
极光代码工作室39 分钟前
基于Hadoop的日志数据分析系统设计
大数据·hadoop·python·数据分析·数据可视化
AAI机器之心1 小时前
这个RAG框架绝了:无论多少跳,LLM只调用两次,成本暴降
人工智能·python·ai·llm·agent·产品经理·rag
Fairy要carry1 小时前
项目01-手搓Agent之loop
前端·javascript·python
郝学胜-神的一滴1 小时前
【技术实战】500G单行大文件读取难题破解!生成器+自定义函数最优方案解析
开发语言·python·程序人生·面试