{"id":57504,"date":"2023-12-23T17:33:12","date_gmt":"2023-12-23T17:33:12","guid":{"rendered":"https:\/\/www.askpython.com\/?p=57504"},"modified":"2025-04-10T20:50:14","modified_gmt":"2025-04-10T20:50:14","slug":"find-where-python-is-installed","status":"publish","type":"post","link":"https:\/\/www.askpython.com\/python\/examples\/find-where-python-is-installed","title":{"rendered":"Finding Where Python Is Installed (when it isn&#8217;t the default dir)"},"content":{"rendered":"\n<p>Python\u2019s interpreter, libraries, and scripts can reside in multiple locations on a system. So, finding where Python is installed helps with:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Locating the&nbsp;<code>python<\/code>&nbsp;executable to launch the interpreter<\/li>\n\n\n\n<li>Editing module files under the Python install\u2019s&nbsp;<code>site-packages<\/code><\/li>\n\n\n\n<li>Modifying scripts under the&nbsp;<code>scripts<\/code>&nbsp;folder of a Python environment<\/li>\n\n\n\n<li>Switching between multiple Python versions using virtual environments<\/li>\n\n\n\n<li>Troubleshooting issues related to Python installations<\/li>\n<\/ul>\n\n\n\n<p>The methods for finding Python\u2019s install location vary across operating systems. In detail, we\u2019ll explore platform-specific techniques on Windows, Linux\/Unix, and macOS. Let&#8217;s jump right in<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"finding-python-on-windows\">Finding Python Location on Windows<\/h2>\n\n\n\n<p>There are several easy methods to find where Python is installed on Windows. Using the&nbsp;<code>where<\/code>&nbsp;command or checking Python\u2019s sys path returns the location.<\/p>\n\n\n\n<p><strong><em>Also read: <a href=\"https:\/\/www.askpython.com\/python\/pipenv-python-packaging-tool\" data-type=\"post\" data-id=\"33280\">Pipenv: The New Packaging Tool For Python<\/a><\/em><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"using-the-where-command\">Using the&nbsp;where&nbsp;Command<\/h3>\n\n\n\n<p>The easiest way is to use the&nbsp;<code>where<\/code>&nbsp;command within the Command Prompt (CMD). Simply open CMD and type:<\/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>Here\u2019s an example output showing the path to the Python interpreter:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nC:\\Users\\gurpreet\\AppData\\Local\\Programs\\Python\\Python310\\python.exe\n\n<\/pre><\/div>\n\n\n<p>So for the sample product data table we imported earlier, we can launch Python from this location:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nC:\\Users\\gurpreet\\AppData\\Local\\Programs\\Python\\Python310\\python.exe\n\nimport pandas as pd\nprint(pd.read_csv(&#039;products.csv&#039;))\n\n<\/pre><\/div>\n\n\n<p>The&nbsp;<code>where<\/code>&nbsp;command also works in PowerShell:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nPS C:\\&gt; where python \nC:\\Users\\gurpreet\\AppData\\Local\\Programs\\Python\\Python310\\python.exe\n\n<\/pre><\/div>\n\n\n<p>On Windows, Python gets added to your system\u2019s PATH environment variable. So running&nbsp;<code>python<\/code>&nbsp;launches the interpreter from any location.<\/p>\n\n\n\n<p>But&nbsp;<code>where python<\/code>&nbsp;returns the actual install location on disk.<\/p>\n\n\n\n<p><strong><em>Also read: <a href=\"https:\/\/www.askpython.com\/python\/examples\/fix-bash-python3-command-not-found\" data-type=\"post\" data-id=\"57312\">[Fix] Bash: Python3: command not found When Installing&nbsp;discord.py&nbsp;on Windows<\/a><\/em><\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"checking-pythons-sys.executable\">Checking Python\u2019s sys.executable<\/h3>\n\n\n\n<p>Another method is using Python\u2019s built-in&nbsp;<code>sys<\/code>&nbsp;module to print the path to the currently running executable:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport sys\nprint(sys.executable)\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nC:\\Users\\gurpreet\\AppData\\Local\\Programs\\Python\\Python310\\python.exe  \n\n<\/pre><\/div>\n\n\n<p>You can also directly run this oneliner from CMD or PowerShell instead of launching Python first:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\npython -c &quot;import sys; print(sys.executable)&quot;\n<\/pre><\/div>\n\n\n<p>So, if you have multiple Python versions installed (eg. Python 2.7, 3.7, 3.10 etc),&nbsp;<code>sys.executable<\/code>&nbsp;points to the specific executable.<\/p>\n\n\n\n<p>This helps when switching between Python installs using virtual environments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"additional-ways-on-windows\">Additional Ways of Finding Python Path on Windows<\/h3>\n\n\n\n<p>Some other methods for locating where Python is installed on Windows include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Searching for&nbsp;<code>python.exe<\/code>&nbsp;using Windows search<\/li>\n\n\n\n<li>Running&nbsp;<code>pip list<\/code>&nbsp;to see packages installed in Python\u2019s&nbsp;<code>site-packages<\/code><\/li>\n\n\n\n<li>Checking the start menu Python folder\u2019s location<\/li>\n\n\n\n<li>Using&nbsp;<code>Get-Command python<\/code>&nbsp;in PowerShell<\/li>\n<\/ul>\n\n\n\n<p>So in summary,&nbsp;<code>where python<\/code>,&nbsp;<code>sys.executable<\/code>, and Windows search makes finding Python installs easy on Windows.<\/p>\n\n\n\n<p>Next, let\u2019s look at Linux\/Unix systems.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"finding-python-on-linuxunix\">Finding Python on Linux\/Unix<\/h2>\n\n\n\n<p>On Linux and Unix-based operating systems like Ubuntu, Debian, CentOS etc, there are simple terminal commands for finding where Python is installed.<\/p>\n\n\n\n<p>The&nbsp;which,&nbsp;type -a, and&nbsp;readlink&nbsp;commands come in handy here.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"using-the-which-command\">Using the&nbsp;which&nbsp;Command<\/h3>\n\n\n\n<p>Most Linux\/Unix systems have Python pre-installed and available globally via the shell.<\/p>\n\n\n\n<p>You can find where it\u2019s located by using&nbsp;<code>which python<\/code>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nwhich python3\n\/usr\/bin\/python3\n<\/pre><\/div>\n\n\n<p>This returns the path to the global Python executable in use.<\/p>\n\n\n\n<p>For our product data example, we can run:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n\/usr\/bin\/python3\n\nimport pandas as pd\nprint(pd.read_csv(&#039;products.csv&#039;)) \n<\/pre><\/div>\n\n\n<p>To find all installed Python versions, use:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nwhich -a python\n\n\/usr\/bin\/python\n\/usr\/bin\/python3  \n\/usr\/local\/bin\/python\n\/home\/preet\/virtualenvs\/analytics\/bin\/python\n<\/pre><\/div>\n\n\n<p>So&nbsp;<code>which python<\/code>&nbsp;helps locate not just the active Python interpreter, but also all available versions on your Linux\/Unix system.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"using-type--a\">Using&nbsp;type -a<\/h3>\n\n\n\n<p>Another option is using the&nbsp;<code>type<\/code>&nbsp;command with the&nbsp;<code>-a<\/code>&nbsp;flag:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ntype -a python\npython is \/usr\/bin\/python\npython is \/usr\/bin\/python3\npython is \/usr\/local\/bin\/python \npython is \/home\/preet\/virtualenvs\/analytics\/bin\/python\n\n<\/pre><\/div>\n\n\n<p>This displays all commands matching the name&nbsp;<code>python<\/code>&nbsp;across directories in your&nbsp;<code>$PATH<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"using-readlink\">Using&nbsp;readlink<\/h3>\n\n\n\n<p>Sometimes Python executables are symbolically linked in the&nbsp;<code>\/usr\/bin<\/code>&nbsp;or&nbsp;<code>\/usr\/local\/bin<\/code>&nbsp;folders to their actual location.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nwhich python3\n\/usr\/bin\/python3\n\n<\/pre><\/div>\n\n\n<p>We can find where this symlink points to using&nbsp;<code>readlink<\/code>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nreadlink -f \/usr\/bin\/python3\n\/usr\/local\/lib\/python3.8\/bin\/python3\n\n<\/pre><\/div>\n\n\n<p>This shows the actual install location to be&nbsp;<code>\/usr\/local\/lib\/python3.8\/<\/code>.<\/p>\n\n\n\n<p>In summary, using&nbsp;<code>which<\/code>,&nbsp;<code>type<\/code>, and&nbsp;<code>readlink<\/code>&nbsp;allows locating both global and virtual environment Python installs on Linux and Unix.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"finding-python-on-macos\">Finding Python on macOS<\/h2>\n\n\n\n<p>On macOS, Python generally gets installed into the&nbsp;<code>\/Library\/<\/code>&nbsp;or&nbsp;<code>~\/Library\/<\/code>&nbsp;folders.<\/p>\n\n\n\n<p>The Finder app provides an easy way to find these locations.<\/p>\n\n\n\n<p>You can also use terminal commands like&nbsp;<code>which<\/code>&nbsp;and&nbsp;<code>sys.executable<\/code>&nbsp;covered earlier.<\/p>\n\n\n\n<p>Let\u2019s go through the Finder approach first.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"using-finder\">Using Finder<\/h3>\n\n\n\n<p>To find where Python is installed on your Mac:<\/p>\n\n\n\n<p><strong>1. Launch Finder and hit&nbsp;<code>Command + Shift + G<\/code><\/strong><\/p>\n\n\n\n<p>This opens the&nbsp;<strong>Go to Folder<\/strong>&nbsp;dialog box.<\/p>\n\n\n\n<p><strong>2. Enter paths like&nbsp;\/Library\/Frameworks\/Python.framework&nbsp;or&nbsp;~\/Library\/Python<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"523\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/12\/image-10-1024x523.png\" alt=\"Image 10\" class=\"wp-image-57505\" style=\"width:644px;height:auto\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/12\/image-10-1024x523.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/12\/image-10-300x153.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/12\/image-10-768x392.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/12\/image-10.png 1144w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Using Command + Shift + G to find Python<\/figcaption><\/figure>\n\n\n\n<p>The&nbsp;<code>\/Library<\/code>&nbsp;path contains Python versions installed system-wide for all users. This includes major versions like:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n\/Library\/Frameworks\/Python.framework\/Versions\/3.11\n\/Library\/Frameworks\/Python.framework\/Versions\/2.7  \n<\/pre><\/div>\n\n\n<p>While the&nbsp;<code>~\/Library<\/code>&nbsp;path has Python installs scoped to your user account. Typically, you\u2019ll find virtual environments here:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n~\/Library\/Python\/3.11\/bin \n<\/pre><\/div>\n\n\n<p><strong>3. Drill down the folders to see the&nbsp;<code>bin\/<\/code>&nbsp;directory containing&nbsp;<code>python3<\/code>.<\/strong><\/p>\n\n\n\n<p>So using Finder provides a graphical way to explore Python install locations on macOS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"additional-ways\">Additional Ways of Finding Python<\/h3>\n\n\n\n<p>As on Linux\/Unix,&nbsp;which python&nbsp;finds the active Python version:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"464\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/12\/image-11-1024x464.png\" alt=\"Image 11\" class=\"wp-image-57506\" style=\"width:590px;height:auto\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/12\/image-11-1024x464.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/12\/image-11-300x136.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/12\/image-11-768x348.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2023\/12\/image-11.png 1396w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nwhich python3\n\/usr\/local\/bin\/python3 \n\n<\/pre><\/div>\n\n\n<p>And&nbsp;<code>sys.executable<\/code>&nbsp;prints the currently running one:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\npython3 -c &quot;import sys; print(sys.executable)&quot;\n\/Users\/preet\/virtualenvs\/analytics\/bin\/python\n\n<\/pre><\/div>\n\n\n<p>These terminal commands work the same on macOS as on Linux.<\/p>\n\n\n\n<p>In summary, Finder and shell commands both provide easy methods for finding Python on macOS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"comparison-of-methods-by-os\">Quick Reference of All Methods By OS<\/h2>\n\n\n\n<p>Here\u2019s a quick comparison table summarizing the different techniques across operating systems:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Operating System<\/th><th>Method<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>Windows<\/td><td>where python<\/td><td>where python<\/td><\/tr><tr><td>Windows<\/td><td>sys.executable<\/td><td>python -c \u201cimport sys; print(sys.executable)\u201d<\/td><\/tr><tr><td>Windows<\/td><td>Get-Command<\/td><td>Get-Command python<\/td><\/tr><tr><td>Linux\/Unix<\/td><td>which python<\/td><td>which python3<\/td><\/tr><tr><td>Linux\/Unix<\/td><td>type -a python<\/td><td>type -a python<\/td><\/tr><tr><td>Linux\/Unix<\/td><td>readlink -f<\/td><td>readlink -f \/usr\/bin\/python<\/td><\/tr><tr><td>macOS<\/td><td>Finder (Ctrl + Shift + G)<\/td><td>\/Library\/Frameworks\/Python.framework<\/td><\/tr><tr><td>macOS<\/td><td>which python<\/td><td>which python3<\/td><\/tr><tr><td>Cross-platform<\/td><td>sys.executable<\/td><td>python -c \u201cimport sys; print(sys.executable)\u201d<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>This covers some easy, go-to approaches for finding Python installs across different OS environments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"summary\">Summary<\/h2>\n\n\n\n<p>Finding where Python is installed is essential for managing multiple versions and virtual environments.<\/p>\n\n\n\n<p>We learned platform-specific techniques for locating Python on Windows, Linux\/Unix and macOS systems:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Windows<\/strong>&nbsp;&#8211; Using&nbsp;<code>where python<\/code>, PowerShell\u2019s&nbsp;<code>Get-Command<\/code>, and&nbsp;<code>sys.executable<\/code><\/li>\n\n\n\n<li><strong>Linux\/Unix<\/strong>&nbsp;&#8211; Leveraging the&nbsp;<code>which<\/code>,&nbsp;<code>type -a<\/code>, and&nbsp;<code>readlink<\/code>&nbsp;terminal commands<\/li>\n\n\n\n<li><strong>macOS<\/strong>&nbsp;&#8211; Finding Python through Finder and shell commands like&nbsp;<code>which<\/code><\/li>\n<\/ul>\n\n\n\n<p>These methods help pinpoint the exact folder containing Python installs.<\/p>\n\n\n\n<p>Knowing the install location allows running Python or its packages, modifying installed scripts, switching between environments, and debugging issues, if any.<\/p>\n\n\n\n<p>Whether you just started with Python or have been using it for a while, finding where Python lives on your OS is an important troubleshooting skill.<\/p>\n\n\n\n<p>So next time you need to locate Python, use this guide to find its path across Windows, Linux and macOS platforms.<\/p>\n\n\n\n<p><strong>References: <\/strong><a href=\"https:\/\/stackoverflow.com\/questions\/6767283\/find-where-python-is-installed-if-it-isnt-default-dir\" target=\"_blank\" rel=\"noopener\">StackOverflow<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u2019s interpreter, libraries, and scripts can reside in multiple locations on a system. So, finding where Python is installed helps with: The methods for finding Python\u2019s install location vary across operating systems. In detail, we\u2019ll explore platform-specific techniques on Windows, Linux\/Unix, and macOS. Let&#8217;s jump right in Finding Python Location on Windows There are several [&hellip;]<\/p>\n","protected":false},"author":77,"featured_media":64134,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-57504","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-examples"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/57504","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\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/comments?post=57504"}],"version-history":[{"count":0,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/57504\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media\/64134"}],"wp:attachment":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media?parent=57504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/categories?post=57504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/tags?post=57504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}