openai command not found (mac)

**题意:**mac 系统上无法识别 openai 的命令

问题背景:

I'm trying to follow the fine tuning guide for Openai here.

我正在尝试遵循 OpenAI 的微调指南

I ran: 我运行以下命令

python 复制代码
pip install --upgrade openai

Which install without any errors. 正常安装,没有任何错误

But even after restarting my terminal, i still get

但是即使我重启了我的终端,我还是得到(某个错误或提示)

python 复制代码
zsh: command not found: openai

Here is the output of echo PATH: 以下是PATH 命令的输出

python 复制代码
/bin:/usr/bin:/usr/local/bin:/Users/nickrose/Downloads/google-cloud-sdk/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Here is the output of which python: 这里 which python 命令的输出

python 复制代码
/usr/bin/python

Any tips for how to fix this? I'm on MacOS Big Sur 11.6.

关于如何解决这个问题,有什么建议吗?我现在使用的是 MacOS Big Sur 11.6。

问题解决:

Basically pip installs the packages under its related python directory, in a directory called site-packages (most likely, I'm not a python expert tbh). This is not included in the path you provided. First, ask pip to show the location to the package:

基本上,pip 将包安装在与其相关的 Python 目录下的名为 site-packages 的目录中(很可能是这样,但我不是 Python 专家,说实话)。这个目录没有包含在您提供的路径中。首先,让 pip 显示包的位置:

python 复制代码
pip show openai

The output would be something like this: 输出将类似于这样:

python 复制代码
Name: openai
Version: 0.22.0
Summary: Python client library for the OpenAI API
Home-page: https://github.com/openai/openai-python
Author: OpenAI
Author-email: support@openai.com
License: 
Location: /Users/<USER>/DIR/TO/SOME/PYTHON/site-packages
Requires: numpy, openpyxl, pandas, pandas-stubs, requests, tqdm
Required-by:

So your package will be available in 所以您的包将可用在

python 复制代码
/Users/<USER>/DIR/TO/SOME/PYTHON/site-packages/openai

Either add /Users/<USER>/DIR/TO/SOME/PYTHON/site-packages/ to your path, or use the complete address to your package, or try to access it using your python:

"要么将 /Users/<USER>/DIR/TO/SOME/PYTHON/site-packages/ 添加到您的路径中,要么使用您的包的完整地址,或者尝试使用您的 Python 访问它"

python 复制代码
python -m openai # -m stands for module

To get more information about the -m flag, run python --help.

要获取关于 -m 标志的更多信息,请运行 python --help

Update

So as you mentioned in the comments, you get permission denied after you add the directory to your package. This actually means that the package exists, but it's not permitted by your OS to execute. This is the thing you have to do, locate your package, and then:

正如您在评论中提到的,在将目录添加到您的包之后,您遇到了"权限被拒绝"的错误。这实际上意味着包是存在的,但是您的操作系统不允许执行它。这是您需要做的,找到您的包,然后:

python 复制代码
sudo chmod +x /PATH/TO/script

And the reason you're getting command not found after you use sudo directly with the package, is that you update your path variable in zsh, but when you use sudo, superuser uses sh instead of zsh.

您在使用 sudo 直接与包一起时遇到 "command not found" 的原因,是因为您在 zsh 中更新了路径变量(PATH),但是当您使用 sudo 时,超级用户(superuser)默认使用 sh 而不是 zsh。这意味着 sudo 命令不会继承您当前 shell(在这个例子中是 zsh)的环境变量,包括 PATH 变量。

相关推荐
西农小陈2 分钟前
Python-基于PyQt5,wordcloud,pillow,numpy,os,sys的智能词云生成器
开发语言·python·小程序·pycharm·numpy·pyqt·pillow
BugNest2 分钟前
计算机视觉和图像处理
图像处理·人工智能·机器学习·计算机视觉·ai
大道戏35 分钟前
如何本地部署DeepSeek
windows·ai·deepseek
Blockchina1 小时前
如何使用 DeepSeek 和 Dexscreener 构建免费的 AI 加密交易机器人?
人工智能·python·ai编程·deepseek
圆圆滚滚小企鹅。1 小时前
刷题记录 贪心算法-3:376. 摆动序列
笔记·python·算法·leetcode·贪心算法
Bran_Liu1 小时前
【LeetCode 刷题】回溯算法-组合问题
python·算法·leetcode
产品媛Gloria Deng2 小时前
分享| RL-GPT 框架通过慢agent和快agent结合提高AI解决复杂任务的能力-Arxiv
人工智能·gpt·ai·agent·ai智能体
加德霍克2 小时前
【机器学习】自定义数据集 使用scikit-learn中svm的包实现svm分类
python·机器学习·支持向量机·scikit-learn·作业
Bran_Liu2 小时前
【LeetCode 刷题】二叉树-二叉搜索树的修改与构造
数据结构·python·算法·leetcode