1、基础环境配置(MAC版)
安装brew
安装地址:https://docs.brew.sh/Installation
安装命令:
#官网原版 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" #国内镜像 /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"安装pyenv:
安装地址:https://github.com/pyenv/pyenv#installation
brew install pyenv
安装python
pyenv install 3.10.4
安装后确认
python3 --version
2、引入python图形化包并编码运行
#推荐先创建虚拟环境
python -m venv venv
source venv/bin/activate
pip install gradio
国内加速
pip install gradio -i https://mirrors.baidu.com/pypi/simple/
import gradio as gr def greet(name): return f"Hello, {name}!" demo = gr.Interface(fn=greet, inputs="text", outputs="text") demo.launch()