{"id":523,"date":"2023-06-27T19:42:07","date_gmt":"2023-06-27T19:42:07","guid":{"rendered":"https:\/\/kevingoedecke.com\/?p=523"},"modified":"2023-06-27T19:42:24","modified_gmt":"2023-06-27T19:42:24","slug":"can-i-use-brew-install-openai-to-install-the-openai-cli","status":"publish","type":"post","link":"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/","title":{"rendered":"Can I use &#8220;brew install openai&#8221; to install the OpenAI CLI?"},"content":{"rendered":"\n<p>Have you been stumped by an error message saying &#8220;command not found: openai&#8221; while trying to get your hands on the OpenAI CLI? I guess your first idea is to install the OpenAI CLI using <a href=\"https:\/\/brew.sh\/\" target=\"_blank\" rel=\"noreferrer noopener\">homebrew<\/a>. After all it&#8217;s everyones favorite package manager on MacOS, right? Well, that was literally my thought process. So I went ahead and tried to execute <code>brew install openai<\/code>. Well turns out homebrew does not have the OpenAI cli in its repository. For this post will guide you through a foolproof installation process to get this situation sorted.<\/p>\n\n\n\n<p>While exploring the possibilities of OpenAI and ChatGPT for training a model on my Intercom customer support chat history, I came across a tutorial on OpenAI&#8217;s platform. This tutorial required me to install the OpenAI CLI. Although the instructions seemed straightforward, running the installation commands yielded the infamous &#8220;command not found: openai&#8221; error. Thus began the journey looking into installing the OpenAI CLI. Side note: It wasn&#8217;t through homebrew.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Problem<\/h2>\n\n\n\n<p>Following the OpenAI guide, I ran the installation command <code>pip install --upgrade openai<\/code>. However, when I attempted <code>openai --help<\/code>, MacOS 13.3 told me that I don&#8217;t have the openai command installed.<\/p>\n\n\n\n<p><code>brew install openai<\/code> didn&#8217;t work either. So I found myself in a situation that required me to dig deeper into the OpenAI CLI installation. Here&#8217;s the step-by-step process I undertook to make it work.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Install OpenAI CLI on MacOS<\/h2>\n\n\n\n<p>There are prerequisites to ensure the smooth installation of the OpenAI CLI. Here&#8217;s a rundown of the necessary steps.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Ensure Python3 Installation<\/h3>\n\n\n\n<p>First and foremost, ensure Python is successfully installed on your machine.<\/p>\n\n\n\n<p>You can verify if Python3 already exists on your system by executing:<\/p>\n\n\n\n<p><code>python3 --version<\/code><\/p>\n\n\n\n<p>If this command returns the Python version, you&#8217;re all set. If not, I suggest you install Python using Homebrew by running:<\/p>\n\n\n\n<p><code>brew install python3<\/code><\/p>\n\n\n\n<p>To confirm a successful installation, execute <code>python3 --version<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">OpenAI CLI Installation via pip<\/h3>\n\n\n\n<p>Though the OpenAI guide suggests <code>pip install --upgrade openai<\/code>, the installation for Python 3 users needs a minor tweak.<\/p>\n\n\n\n<p>To install the OpenAI CLI, use:<\/p>\n\n\n\n<p><code>pip3 install --upgrade openai<\/code><\/p>\n\n\n\n<p>Attempting <code>openai --help<\/code> at this point might still result in a &#8220;command not found&#8221; error. The subsequent steps address this issue.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Making OpenAI CLI Executable<\/h3>\n\n\n\n<p>Next, we need to create a binary file in the local user&#8217;s bin directory (\/usr\/local\/bin), which holds all user-specific executable binaries.<\/p>\n\n\n\n<p>Run the following command:<\/p>\n\n\n\n<p><code>sudo sh -c 'echo python3 \"$(python3 -m site --user-site)\"\/openai\/_openai_scripts.py \\$\\@ &gt; \/usr\/local\/bin\/openai'<\/code><\/p>\n\n\n\n<p>This command essentially does three things:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It obtains the path to the directory containing globally installed Python packages: <code>python3 -m site --user-site<\/code>.<\/li>\n\n\n\n<li>It extends the path to the OpenAI CLI scripts Python script: <code>openai\/_openai_scripts.py<\/code>.<\/li>\n\n\n\n<li>It writes this extended path into a file in the \/usr\/local\/bin directory, enabling it to be used as a shell command from any location.<\/li>\n<\/ul>\n\n\n\n<p>Lastly, we need to ensure the file is executable by running:<\/p>\n\n\n\n<p><code>sudo chmod +x \/usr\/local\/bin\/openai<\/code><\/p>\n\n\n\n<p>This final step should allow you to use the OpenAI CLI from anywhere in your terminal.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Testing the Installation<\/h3>\n\n\n\n<p>To verify if everything is correctly set up, execute:<\/p>\n\n\n\n<p><code>openai --help<\/code><\/p>\n\n\n\n<p>This command should return all available OpenAI CLI commands, indicating a successful installation.<\/p>\n\n\n\n<p>And there you have it \u2013 a comprehensive guide on installing the OpenAI CLI on MacOS. Feel free to leave a comment if you have any queries or run into any trouble during the process. And all that without homebrew. Maybe one day brew will add a package to support installing the cli tool by just running brew install openai.<\/p>\n\n\n\n<p>Cheers<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you been stumped by an error message saying &#8220;command not found: openai&#8221; while trying to get your hands on the OpenAI CLI? I guess your first idea is to install the OpenAI CLI using homebrew. After all it&#8217;s everyones favorite package manager on MacOS, right? Well, that was literally my thought process. So I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":525,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[57],"tags":[],"class_list":["post-523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chatgpt"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Can I use &quot;brew install openai&quot; to install the OpenAI CLI? - Kevin Goedecke<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Can I use &quot;brew install openai&quot; to install the OpenAI CLI? - Kevin Goedecke\" \/>\n<meta property=\"og:description\" content=\"Have you been stumped by an error message saying &#8220;command not found: openai&#8221; while trying to get your hands on the OpenAI CLI? I guess your first idea is to install the OpenAI CLI using homebrew. After all it&#8217;s everyones favorite package manager on MacOS, right? Well, that was literally my thought process. So I [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/\" \/>\n<meta property=\"og:site_name\" content=\"Kevin Goedecke\" \/>\n<meta property=\"article:published_time\" content=\"2023-06-27T19:42:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-27T19:42:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/06\/openai-brew-install-banner.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1800\" \/>\n\t<meta property=\"og:image:height\" content=\"900\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Kevin Goedecke\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kevin Goedecke\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/\",\"url\":\"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/\",\"name\":\"Can I use \\\"brew install openai\\\" to install the OpenAI CLI? - Kevin Goedecke\",\"isPartOf\":{\"@id\":\"https:\/\/kevingoedecke.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/06\/openai-brew-install-banner.jpg\",\"datePublished\":\"2023-06-27T19:42:07+00:00\",\"dateModified\":\"2023-06-27T19:42:24+00:00\",\"author\":{\"@id\":\"https:\/\/kevingoedecke.com\/#\/schema\/person\/4b156cd6453e1af4bab9076b0a663871\"},\"breadcrumb\":{\"@id\":\"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/#primaryimage\",\"url\":\"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/06\/openai-brew-install-banner.jpg\",\"contentUrl\":\"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/06\/openai-brew-install-banner.jpg\",\"width\":1800,\"height\":900},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/kevingoedecke.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Can I use &#8220;brew install openai&#8221; to install the OpenAI CLI?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/kevingoedecke.com\/#website\",\"url\":\"https:\/\/kevingoedecke.com\/\",\"name\":\"Kevin Goedecke\",\"description\":\"Founder. Entrepreneur.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/kevingoedecke.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/kevingoedecke.com\/#\/schema\/person\/4b156cd6453e1af4bab9076b0a663871\",\"name\":\"Kevin Goedecke\",\"url\":\"https:\/\/kevingoedecke.com\/blog\/author\/kgoedecke\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Can I use \"brew install openai\" to install the OpenAI CLI? - Kevin Goedecke","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/","og_locale":"en_US","og_type":"article","og_title":"Can I use \"brew install openai\" to install the OpenAI CLI? - Kevin Goedecke","og_description":"Have you been stumped by an error message saying &#8220;command not found: openai&#8221; while trying to get your hands on the OpenAI CLI? I guess your first idea is to install the OpenAI CLI using homebrew. After all it&#8217;s everyones favorite package manager on MacOS, right? Well, that was literally my thought process. So I [&hellip;]","og_url":"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/","og_site_name":"Kevin Goedecke","article_published_time":"2023-06-27T19:42:07+00:00","article_modified_time":"2023-06-27T19:42:24+00:00","og_image":[{"width":1800,"height":900,"url":"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/06\/openai-brew-install-banner.jpg","type":"image\/jpeg"}],"author":"Kevin Goedecke","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kevin Goedecke","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/","url":"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/","name":"Can I use \"brew install openai\" to install the OpenAI CLI? - Kevin Goedecke","isPartOf":{"@id":"https:\/\/kevingoedecke.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/#primaryimage"},"image":{"@id":"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/#primaryimage"},"thumbnailUrl":"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/06\/openai-brew-install-banner.jpg","datePublished":"2023-06-27T19:42:07+00:00","dateModified":"2023-06-27T19:42:24+00:00","author":{"@id":"https:\/\/kevingoedecke.com\/#\/schema\/person\/4b156cd6453e1af4bab9076b0a663871"},"breadcrumb":{"@id":"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/#primaryimage","url":"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/06\/openai-brew-install-banner.jpg","contentUrl":"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/06\/openai-brew-install-banner.jpg","width":1800,"height":900},{"@type":"BreadcrumbList","@id":"https:\/\/kevingoedecke.com\/blog\/2023\/06\/27\/can-i-use-brew-install-openai-to-install-the-openai-cli\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kevingoedecke.com\/"},{"@type":"ListItem","position":2,"name":"Can I use &#8220;brew install openai&#8221; to install the OpenAI CLI?"}]},{"@type":"WebSite","@id":"https:\/\/kevingoedecke.com\/#website","url":"https:\/\/kevingoedecke.com\/","name":"Kevin Goedecke","description":"Founder. Entrepreneur.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kevingoedecke.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/kevingoedecke.com\/#\/schema\/person\/4b156cd6453e1af4bab9076b0a663871","name":"Kevin Goedecke","url":"https:\/\/kevingoedecke.com\/blog\/author\/kgoedecke\/"}]}},"jetpack_featured_media_url":"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/06\/openai-brew-install-banner.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/posts\/523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/comments?post=523"}],"version-history":[{"count":1,"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/posts\/523\/revisions"}],"predecessor-version":[{"id":524,"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/posts\/523\/revisions\/524"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/media\/525"}],"wp:attachment":[{"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/media?parent=523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/categories?post=523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/tags?post=523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}