【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 分钟前
STL -- C++ 红黑树封装 Map 和 Set
java·c语言·开发语言·c++·面试
Tbisnic5 分钟前
23.大模型开发:深度学习----CNN 卷积神经网络 与 RNN 循环神经网络
人工智能·python·rnn·深度学习·cnn·ai大模型
小园子的小菜8 分钟前
Java核心基础:反射与泛型底层原理及实战用法详解
java·开发语言
十五年专注C++开发34 分钟前
C++之std::numeric_limits介绍
开发语言·c++·limits
2501_9259633836 分钟前
Hi3516 + WS73 SDIO Wi-Fi 适配笔记
java·开发语言
CoderYanger38 分钟前
视频切割脚本(Python版)
linux·开发语言·windows·后端·python·程序人生·职场和发展
辞旧 lekkk38 分钟前
CMake工程指南(一)
linux·运维·服务器·开发语言·qt·学习·萌新
迷途呀41 分钟前
新闻头条后端:新闻缓存模块
前端·redis·python·缓存·fastapi
想会飞的蒲公英1 小时前
逻辑回归为什么叫回归,却用来做分类
人工智能·python·分类·回归·逻辑回归
小七在进步1 小时前
数据结构:用栈实现队列
开发语言·数据结构