【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.
相关推荐
天天被压力2 分钟前
【Python 量化取数指南 #13】Python 把行情落库:sqlite 一键存,回测随用随取
java·人工智能·python
天天被压力2 分钟前
【Python 量化取数指南 #14】Python 清洗行情数据:复权停牌对齐,回测不翻车
java·人工智能·python
Python私教2 分钟前
Python环境配置:conda+PyCharm+换源,附6个坑
人工智能·python·pycharm
大熊猫侯佩3 分钟前
macOS27 上可变界面尺寸 iOS App 揭秘
macos·ios·swiftui
databook5 分钟前
检测数据异常值的五种统计技术
python·数据挖掘·数据分析
小小张说故事5 分钟前
Selenium 装驱动太麻烦?Playwright 入门指南:Python 网页自动化新标准
python
tangzzzfan5 分钟前
把 ADB 装进 macOS app
macos
海宇数科5 分钟前
Python数据工程:利用海宇车型识别精准优化车险理赔合规体验
人工智能·python
小小张说故事6 分钟前
不会前端怎么做数据网页?Streamlit 入门指南:几行 Python 变出可交互应用
python·数据可视化
子兮曰7 分钟前
Laya 深度解析:421M 开源决策模型硬刚 Jev,33ms 背后藏了啥
前端·后端·python