{"id":52862,"date":"2023-06-30T08:54:34","date_gmt":"2023-06-30T08:54:34","guid":{"rendered":"https:\/\/www.askpython.com\/?p=52862"},"modified":"2026-09-29T18:00:56","modified_gmt":"2026-09-29T18:00:56","slug":"determine-install-path-of-python-cli","status":"publish","type":"post","link":"https:\/\/www.askpython.com\/python\/examples\/determine-install-path-of-python-cli","title":{"rendered":"Determining the Install Path of Python from the Command Line"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Knowing where your files are located in your local system is always essential. It helps you to easily access folders and manipulate them via various applications or commands. You can always change the path of your installed applications through more than one method in Python. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An absolute or relative path of a particular file or folder in your computer will give you an idea of the file hierarchy system. It is the location of a text, photo or video stored inside your laptop or desktop. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We must know the path to the Python GUI to write our programs. Otherwise, it becomes difficult to install modules or libraries in the future. If our Python is stored in the D drive and the modules are stored in C, it might cause problems when we try to import them and use them in our programs. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Adding Python to the PATH Environment Variable<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You must have seen in tutorials regarding <a href=\"https:\/\/www.python.org\/\" data-type=\"URL\" data-id=\"https:\/\/www.python.org\/\" target=\"_blank\" rel=\"noopener\">Python installation<\/a>, it is always advised to add Python to PATH. What does this mean? It means that you are making Python commands accessible from your command prompt. It allows you to access the python shell from your command prompt. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is important for future use because you will be using the PIP(the full form is pip installs packages) which is a package installer for Python. Hence, if Python is added to your PATH then it becomes easier and more accessible via the command prompt for future installations. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method 1: Locating Python in Windows Using the &#8216;where&#8217; Command<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In windows, go to your search bar, and write cmd or command prompt in it. Or, press windows key + R, and open &#8220;cmd&#8221;.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/The-command-prompt-1024x512.png\" alt=\"The Command Prompt\" class=\"wp-image-52942\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/The-command-prompt-1024x512.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/The-command-prompt-300x150.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/The-command-prompt-768x384.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/The-command-prompt.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">The Command Prompt<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now we&#8217;ll run the following command in our command prompt to find the location of Python in our computer. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nwhere python\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Now press &#8220;Enter&#8221;. The keyword &#8220;where&#8221; will give you the absolute path of Python as shown below.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nC:\\Users\\SHREYA\\AppData\\Local\\Programs\\Python\\Python311\\python.exe\nC:\\Users\\SHREYA\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-where-keyword-1024x512.png\" alt=\"Using The Where Keyword\" class=\"wp-image-52945\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-where-keyword-1024x512.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-where-keyword-300x150.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-where-keyword-768x384.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-where-keyword.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Using the &#8216;where&#8217; Keyword<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Method 2: Locating Python in Windows Using the &#8216;&#8211;list-paths&#8217; Option<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There is another way to locate your Python installation files using the command line. You can use the list keyword to locate Python. Run the following command in your command prompt. This command also tells you about the version installed. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\npy --list-paths\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The output would be:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n -V:3.11 *        C:\\Users\\SHREYA\\AppData\\Local\\Programs\\Python\\Python311\\python.exe\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-list-keyword-1024x512.png\" alt=\"Using The List Keyword\" class=\"wp-image-52949\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-list-keyword-1024x512.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-list-keyword-300x150.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-list-keyword-768x384.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-list-keyword.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Using The List Keyword<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Method 3: Locating Python in Windows Using the &#8216;python&#8217; Command<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In windows, this is the most simple way to find out information of Python. Just write the word python in your command prompt and hit &#8220;Enter&#8221; as shown below.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\npython\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The output would be something as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nPython 3.11.1 (tags\/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) &#x5B;MSC v.1934 64 bit (AMD64)] on win32\nType &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-python-word-1024x512.png\" alt=\"Using The Python Word\" class=\"wp-image-52956\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-python-word-1024x512.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-python-word-300x150.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-python-word-768x384.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-python-word.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Using The Python Word<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Similar: <a href=\"https:\/\/www.askpython.com\/python\/examples\/extract-file-name-from-path\" data-type=\"post\" data-id=\"48855\">Extract File Name from Path for Any OS\/Path Format.<\/a><\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method 4: Locating Python in Windows Using the &#8216;os&#8217; and &#8216;sys&#8217; Modules<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The python os module and the systems module(sys) are modules that are in built and comes preinstalled with the default Python installation. They help us interact with the operating system via Python code. You can also import them and run commands to find the location of the Python executable file on your computer in the following way:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\npython\n&gt;&gt;&gt;import os\n&gt;&gt;&gt;import sys\n&gt;&gt;&gt;print(os.path.dirname(sys.executable))\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The output will give you the location of the Python.exe file in your system.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nC:\\Users\\SHREYA\\AppData\\Local\\Programs\\Python\\Python311\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-o-and-sys-modules-from-Python-itself-1024x512.png\" alt=\"Using The O And Sys Modules From Python Itself\" class=\"wp-image-52963\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-o-and-sys-modules-from-Python-itself-1024x512.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-o-and-sys-modules-from-Python-itself-300x150.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-o-and-sys-modules-from-Python-itself-768x384.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/06\/Using-the-o-and-sys-modules-from-Python-itself.png 1200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Using The O And Sys Modules From Python Itself<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Also check out: <a href=\"https:\/\/www.askpython.com\/python\/examples\/list-files-in-a-directory-using-python\" data-type=\"post\" data-id=\"7412\">How to List Files in a Directory Using Python?<\/a><\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Locating Python on a Linux System<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">On your Linux system, open the terminal and type in:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nwhich python or which python3\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">This will give you the current active location of Python on your Linux system. It is mostly found in the user\/bin\/ directory. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Locating Python on a macOS System<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">On your mac, click on the launchpad icon and search for the terminal. In your Terminal, type the following:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nwhich python\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">This will give you the absolute path of Python on your mac. It is mainly stored in \/Library\/Frameworks\/Python\/Versions<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion: Locate the Python Installation Path Effortlessly<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we have seen how important it is to add Python to PATH to make it accessible through our command prompt. On Windows, there are 4 different methods via which you can find the location where your Python is present. On other operating systems such as Linux and macOS, there are also ways to determine the installed Python path. All of these methods are straightforward and can help you locate the Python installation directory for future package or module installations. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Knowing where your files are located in your local system is always essential. It helps you to easily access folders and manipulate them via various applications or commands. You can always change the path of your installed applications through more than one method in Python. An absolute or relative path of a particular file or [&hellip;]<\/p>\n","protected":false},"author":49,"featured_media":70608,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-52862","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-examples"],"_links":{"self":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/52862","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/users\/49"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/comments?post=52862"}],"version-history":[{"count":0,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/52862\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media\/70608"}],"wp:attachment":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media?parent=52862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/categories?post=52862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/tags?post=52862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}