{"id":453,"date":"2023-04-14T15:00:48","date_gmt":"2023-04-14T15:00:48","guid":{"rendered":"https:\/\/kevingoedecke.com\/?p=453"},"modified":"2023-04-14T15:08:37","modified_gmt":"2023-04-14T15:08:37","slug":"how-to-install-openai-cli-on-macos","status":"publish","type":"post","link":"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/","title":{"rendered":"How to Install OpenAI CLI on MacOS"},"content":{"rendered":"\n<p>Did you also get hit with a <code>command not found: openai<\/code> error? Let&#8217;s figure out how to install the OpenAI CLI and how to fix this issue. <\/p>\n\n\n\n<p>Throughout the past week I&#8217;ve been dabbling with OpenAI and ChatGPT. My goal was to fine tune a model with our existing Intercom customer support chat history to potentially enable a bot to reply or suggest replies. After writing a script that would export all of our conversations from Intercom I wanted to start fine tuning the model. I was following this tutorial here: https:\/\/platform.openai.com\/docs\/guides\/fine-tuning, which required me to install the OpenAI CLI. Weirdly I couldn&#8217;t get this to work and the instructions weren&#8217;t very clear on how to get it going. <\/p>\n\n\n\n<p>Disclaimer: I&#8217;m not a massive Python geek&#8230; I know my way around pip and Python but I&#8217;m certainly not an expert.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The issue<\/h2>\n\n\n\n<p>In the OpenAI documentation the instructions literally just state to run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install --upgrade openai<\/code><\/pre>\n\n\n\n<p>but after running that, I tried to execute <code>openai --help<\/code> and was greeted with the following error \ud83d\ude2a&#8230;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>zsh: command not found: openai<\/code><\/pre>\n\n\n\n<p>I&#8217;m on MacOS 13.3 and it gave me back a command not found error for the openai command.<\/p>\n\n\n\n<p>So I had to dig my way through installing the OpenAI CLI properly. Here&#8217;s how I did it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing the OpenAI CLI on MacOS<\/h2>\n\n\n\n<p>In order to properly install the OpenAI CLI on Mac you need to first make sure a few requirements are met.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install Python3<\/h3>\n\n\n\n<p>The first thing you need to do is make sure that Python is properly installed on your Mac.<\/p>\n\n\n\n<p>To check if you already have Python3 installed run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python3 --version<\/code><\/pre>\n\n\n\n<p>If this gives you back the Python version, then you&#8217;re good to proceed to the next step.<\/p>\n\n\n\n<p>Otherwise I would recommend you to install Python using homebrew:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew install python3<\/code><\/pre>\n\n\n\n<p>Afterwards you should double check if the installation was successful by running <code>python3 --version<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install OpenAI CLI with pip<\/h3>\n\n\n\n<p>The OpenAI documentation says to run <code>pip install --upgrade openai<\/code> but since we&#8217;re using Python 3 we need to adjust this a bit.<\/p>\n\n\n\n<p>Run the following command to install the OpenAI CLI<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip3 install --upgrade openai<\/code><\/pre>\n\n\n\n<p>If you now run <code>openai --help<\/code> you will still get an error message, telling you <code>command not found<\/code>.<\/p>\n\n\n\n<p>The next step is to make the Python OpenAI script executable and add it to our path.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Make the OpenAI CLI executable<\/h3>\n\n\n\n<p>We will have to create a binary file in your local users bin directory (<code>\/usr\/local\/bin<\/code>). This directory contains all executable binaries that are specific to your user.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo sh -c 'echo python3 \"$(python3 -m site --user-site)\"\/openai\/_openai_scripts.py \\$\\@ &gt; \/usr\/local\/bin\/openai'<\/code><\/pre>\n\n\n\n<p>What this command does is the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We get the path to the python site packages directory where all global python packages are installed to: <code>python3 -m site --user-site<\/code><\/li>\n\n\n\n<li>We extend that path to map to the OpenAI CLI scripts Python script: <code>openai\/_openai_scripts.py<\/code>)<\/li>\n\n\n\n<li>We then pipe this into a file in the <code>\/usr\/local\/bin<\/code> directory to use it from anywhere as a shell command<\/li>\n<\/ul>\n\n\n\n<p>The last thing we need to do now is to make that file executable:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chmod +x \/usr\/local\/bin\/openai<\/code><\/pre>\n\n\n\n<p>This should be it, you should now be able to run the OpenAI CLI from anywhere in your terminal.<\/p>\n\n\n\n<p>You can test this by doing the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openai --help<\/code><\/pre>\n\n\n\n<p>Which should return all available OpenAI CLI commands.<\/p>\n\n\n\n<p>That&#8217;s it, if you have any questions or issues setting this up, feel free to leave a comment.<\/p>\n\n\n\n<p>Happy building folks \ud83e\udd16<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you also get hit with a command not found: openai error? Let&#8217;s figure out how to install the OpenAI CLI and how to fix this issue. Throughout the past week I&#8217;ve been dabbling with OpenAI and ChatGPT. My goal was to fine tune a model with our existing Intercom customer support chat history to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":456,"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":[1],"tags":[],"class_list":["post-453","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Install OpenAI CLI on MacOS - 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\/04\/14\/how-to-install-openai-cli-on-macos\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Install OpenAI CLI on MacOS - Kevin Goedecke\" \/>\n<meta property=\"og:description\" content=\"Did you also get hit with a command not found: openai error? Let&#8217;s figure out how to install the OpenAI CLI and how to fix this issue. Throughout the past week I&#8217;ve been dabbling with OpenAI and ChatGPT. My goal was to fine tune a model with our existing Intercom customer support chat history to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/\" \/>\n<meta property=\"og:site_name\" content=\"Kevin Goedecke\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-14T15:00:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-14T15:08:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/04\/openai-command-not-found.png\" \/>\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\/png\" \/>\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\/04\/14\/how-to-install-openai-cli-on-macos\/\",\"url\":\"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/\",\"name\":\"How to Install OpenAI CLI on MacOS - Kevin Goedecke\",\"isPartOf\":{\"@id\":\"https:\/\/kevingoedecke.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/04\/openai-command-not-found.png\",\"datePublished\":\"2023-04-14T15:00:48+00:00\",\"dateModified\":\"2023-04-14T15:08:37+00:00\",\"author\":{\"@id\":\"https:\/\/kevingoedecke.com\/#\/schema\/person\/4b156cd6453e1af4bab9076b0a663871\"},\"breadcrumb\":{\"@id\":\"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/#primaryimage\",\"url\":\"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/04\/openai-command-not-found.png\",\"contentUrl\":\"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/04\/openai-command-not-found.png\",\"width\":1800,\"height\":900},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/kevingoedecke.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Install OpenAI CLI on MacOS\"}]},{\"@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":"How to Install OpenAI CLI on MacOS - 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\/04\/14\/how-to-install-openai-cli-on-macos\/","og_locale":"en_US","og_type":"article","og_title":"How to Install OpenAI CLI on MacOS - Kevin Goedecke","og_description":"Did you also get hit with a command not found: openai error? Let&#8217;s figure out how to install the OpenAI CLI and how to fix this issue. Throughout the past week I&#8217;ve been dabbling with OpenAI and ChatGPT. My goal was to fine tune a model with our existing Intercom customer support chat history to [&hellip;]","og_url":"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/","og_site_name":"Kevin Goedecke","article_published_time":"2023-04-14T15:00:48+00:00","article_modified_time":"2023-04-14T15:08:37+00:00","og_image":[{"width":1800,"height":900,"url":"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/04\/openai-command-not-found.png","type":"image\/png"}],"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\/04\/14\/how-to-install-openai-cli-on-macos\/","url":"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/","name":"How to Install OpenAI CLI on MacOS - Kevin Goedecke","isPartOf":{"@id":"https:\/\/kevingoedecke.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/#primaryimage"},"image":{"@id":"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/#primaryimage"},"thumbnailUrl":"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/04\/openai-command-not-found.png","datePublished":"2023-04-14T15:00:48+00:00","dateModified":"2023-04-14T15:08:37+00:00","author":{"@id":"https:\/\/kevingoedecke.com\/#\/schema\/person\/4b156cd6453e1af4bab9076b0a663871"},"breadcrumb":{"@id":"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/#primaryimage","url":"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/04\/openai-command-not-found.png","contentUrl":"https:\/\/kevingoedecke.com\/blog\/wp-content\/uploads\/2023\/04\/openai-command-not-found.png","width":1800,"height":900},{"@type":"BreadcrumbList","@id":"https:\/\/kevingoedecke.com\/blog\/2023\/04\/14\/how-to-install-openai-cli-on-macos\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kevingoedecke.com\/"},{"@type":"ListItem","position":2,"name":"How to Install OpenAI CLI on MacOS"}]},{"@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\/04\/openai-command-not-found.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/posts\/453","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=453"}],"version-history":[{"count":3,"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/posts\/453\/revisions"}],"predecessor-version":[{"id":457,"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/posts\/453\/revisions\/457"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/media\/456"}],"wp:attachment":[{"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/media?parent=453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/categories?post=453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kevingoedecke.com\/blog\/wp-json\/wp\/v2\/tags?post=453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}