OpenAI的python接口版本要求: python >= 3.9
, openai的版本至少是0.27
venv 和 anaconda 二选一,推荐anaconda
venv 是python3.3标准库自带的虚拟环境库
python -m venv your_env_name # -m 把模块当作脚本运行
source <环境名称>/bin/activate
deactivate
需要先安装 anaconda
conda create -n my_python3.10_env python=3.10
source activate my_python3.10_env
# 或者
conda activate my_python3.10_env
conda deactivate
conda env list
conda env remove -n env_name -all
conda update -n base conda
- 运行
anaconda-clean
conda install anaconda-clean anaconda-clean
- 删除Anaconda目录,Anaconda的安装文件都包含在一个目录中,所以直接将该目录删除即可。
conda info
可以查看到当初 anaconda 安装所在目录 - 删除
~/.bash_profile
中anaconda的环境变量,使用vim打开删除;Anaconda在安装的时候,会自动在~/.bash_profile
加入一些环境变量。
pip install openai
python test.py
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
By running pip install setuptools --upgrade
fixed the version with Successfully installed setuptools-67.2.0