I want to find out my Python installation path on Windows. For example:
C:Python25
How can I find where Python is installed?
Stevoisiak
23.1k27 gold badges120 silver badges222 bronze badges
asked Mar 15, 2009 at 9:09
Fang-Pen LinFang-Pen Lin
13.2k15 gold badges66 silver badges95 bronze badges
1
In your Python interpreter, type the following commands:
>>> import os
>>> import sys
>>> os.path.dirname(sys.executable)
'C:\Python25'
Also, you can club all these and use a single line command. Open cmd and enter following command
python -c "import os, sys; print(os.path.dirname(sys.executable))"
answered Mar 15, 2009 at 13:17
13
If you have Python in your environment variable then you can use the following command in cmd or powershell:
where python
or for Unix enviroment
which python
command line image :
answered Apr 17, 2017 at 16:04
Aekansh KansalAekansh Kansal
2,6991 gold badge14 silver badges17 bronze badges
3
It would be either of
- C:Python36
- C:Users(Your logged in User)AppDataLocalProgramsPythonPython36
answered Aug 18, 2017 at 9:52
Amol ManthalkarAmol Manthalkar
1,8501 gold badge16 silver badges16 bronze badges
5
If you need to know the installed path under Windows without starting the python interpreter, have a look in the Windows registry.
Each installed Python version will have a registry key in either:
HKLMSOFTWAREPythonPythonCoreversionnumberInstallPath
HKCUSOFTWAREPythonPythonCoreversionnumberInstallPath
In 64-bit Windows, it will be under the Wow6432Node
key:
HKLMSOFTWAREWow6432NodePythonPythonCoreversionnumberInstallPath
yincrash
6,3341 gold badge39 silver badges41 bronze badges
answered Mar 15, 2009 at 21:08
codeapecodeape
97.1k24 gold badges156 silver badges186 bronze badges
8
Simple way is
- open CMD
- type
where python
in cmd
answered Jan 30, 2020 at 14:13
BigData-GuruBigData-Guru
1,1211 gold badge14 silver badges20 bronze badges
2
If you have the py
command installed, which you likely do, then just use the --list-paths
/-0p
argument to the command:
py --list-paths
Example output:
Installed Pythons found by py Launcher for Windows
-3.8-32 C:UserscscottAppDataLocalProgramsPythonPython38-32python.exe *
-2.7-64 C:Python27python.exe
The * indicates the currently active version for scripts executed using the py
command.
answered Dec 9, 2019 at 20:48
carlin.scottcarlin.scott
5,9643 gold badges29 silver badges34 bronze badges
1
On my windows installation, I get these results:
>>> import sys
>>> sys.executable
'C:\Python26\python.exe'
>>> sys.platform
'win32'
>>>
(You can also look in sys.path
for reasonable locations.)
answered Mar 15, 2009 at 10:18
gimelgimel
82.7k10 gold badges76 silver badges104 bronze badges
2
Its generally
‘C:Usersuser-nameAppDataLocalProgramsPythonPython-version’
or
try using (in cmd )
where python
answered Apr 12, 2020 at 18:45
In the sys
package, you can find a lot of useful information about your installation:
import sys
print sys.executable
print sys.exec_prefix
I’m not sure what this will give on your Windows system, but on my Mac executable
points to the Python binary and exec_prefix
to the installation root.
You could also try this for inspecting your sys
module:
import sys
for k,v in sys.__dict__.items():
if not callable(v):
print "%20s: %s" % (k,repr(v))
answered Mar 15, 2009 at 9:41
Guðmundur HGuðmundur H
11.3k3 gold badges24 silver badges22 bronze badges
2
If You want the Path After successful installation then first open you CMD and type
python or python -i
It Will Open interactive shell for You and Then type
import sys
sys.executable
Hit enter and you will get path where your python is installed …
answered Oct 18, 2018 at 7:30
1
To know where Python is installed you can execute where python
in your cmd.exe.
anothernode
4,99911 gold badges43 silver badges60 bronze badges
answered Jul 27, 2018 at 6:21
4
You can search for the “environmental variable for you account”. If you have added the Python in the path, it’ll show as “path” in your environmental variable account.
but almost always you will find it in
“C:Users%User_name%AppDataLocalProgramsPythonPython_version”
the ‘AppData‘ folder may be hidden, make it visible from the view section of toolbar.
answered Sep 14, 2018 at 9:19
Amit GuptaAmit Gupta
2,6604 gold badges23 silver badges37 bronze badges
Make use of the Python Launcher for Windows (available as of 3.3). It is compatible with all available versions of python.
First, check if the launcher is available:
py
starts the latest installed version of Python
To see all Python versions available on your system and their path:
py -0p
or
py --list-paths
For a specific Python version path—especially useful with multiple python installations:
py -3.7 -c "import os, sys; print(os.path.dirname(sys.executable))"
python 2
py -2 -c "import os, sys; print(os.path.dirname(sys.executable))"
py
installed location is C:Windowspy.exe
if installed for all users, otherwise can be found at C:UsersusernameAppDataLocalProgramsPythonLauncher
.
It does not require the environment PATH
variable to be set if installed for all users.
answered Apr 25, 2022 at 2:23
oyeyipooyeyipo
3493 silver badges11 bronze badges
You can find it in the Windows GUI, but you need to select “show hidden” in the menu. Directory where python is installed on my Win10 computer:
C:UsersusernameAppDataLocalProgramsPythonPython310
Very handy if you use python pip to install packages.
Suraj Rao
29.3k11 gold badges94 silver badges103 bronze badges
answered Dec 31, 2021 at 14:35
1
If anyone needs to do this in C# I’m using the following code:
static string GetPythonExecutablePath(int major = 3)
{
var software = "SOFTWARE";
var key = Registry.CurrentUser.OpenSubKey(software);
if (key == null)
key = Registry.LocalMachine.OpenSubKey(software);
if (key == null)
return null;
var pythonCoreKey = key.OpenSubKey(@"PythonPythonCore");
if (pythonCoreKey == null)
pythonCoreKey = key.OpenSubKey(@"Wow6432NodePythonPythonCore");
if (pythonCoreKey == null)
return null;
var pythonVersionRegex = new Regex("^" + major + @".(d+)-(d+)$");
var targetVersion = pythonCoreKey.GetSubKeyNames().
Select(n => pythonVersionRegex.Match(n)).
Where(m => m.Success).
OrderByDescending(m => int.Parse(m.Groups[1].Value)).
ThenByDescending(m => int.Parse(m.Groups[2].Value)).
Select(m => m.Groups[0].Value).First();
var installPathKey = pythonCoreKey.OpenSubKey(targetVersion + @"InstallPath");
if (installPathKey == null)
return null;
return (string)installPathKey.GetValue("ExecutablePath");
}
answered Apr 5, 2017 at 11:10
PeterPeter
36.7k38 gold badges141 silver badges197 bronze badges
2
This worked for me: C:UsersYour_user_nameAppDataLocalProgramsPython
My currently installed python version
is 3.7.0
Hope this helps!
David
1,1825 gold badges13 silver badges30 bronze badges
answered Jul 16, 2018 at 6:55
Go to C:UsersUSERAppDataLocalProgramsPythonPython36
if it is not there then
open console by windows+^R
Then type cmd and hit enter
type python if installed in your local file it will show you its version from there type the following
import os
import sys
os.path.dirname(sys.executable)
answered Mar 1, 2019 at 11:34
You could have many versions of Python installed on your machine. So if you’re in Windows at a command prompt, entering something like this…
py --version
…should tell you what version you’re using at the moment. (Maybe replace py
with python
or python3
if py doesn’t work). Anyway you’d see something like
Python 3.10.2
If you then create a virtual environment using something like this…
py -m venv venv
…that environment will also use that Python version. To verify, activate the environment…
venvscriptsactivate.bat
You’ll see the name of the command prompt. Now if execute:
where python
…it will show you which Python executable that virtual environment uses. It will be a copy of Python.exe what’s actually in the Scripts subfolder of the virtual environment folder. Of course to see which version that is, again use py --version
.
answered Jan 26, 2022 at 15:55
if you still stuck or you get this
C:\Users\name of your\AppData\Local\Programs\Python\Python36
simply do this replace 2 with one
C:UsersakshayAppDataLocalProgramsPythonPython36
Kos
4,8709 gold badges38 silver badges42 bronze badges
answered Jun 2, 2018 at 16:48
I installed 2 and 3 and had the same problem finding 3. Fortunately, typing path at the windows path let me find where I had installed it. The path was an option when I installed Python which I just forgot. If you didn’t select setting the path when you installed Python 3 that probably won’t work – unless you manually updated the path when you installed it.
In my case it was at c:Program FilesPython37python.exe
answered Feb 3, 2019 at 16:39
If you use anaconda navigator
on windows, you can go too enviornments
and scroll over the enviornments, the root
enviorment will indicate where it is installed. It can help if you want to use this enviorment when you need to connect this to other applications, where you want to integrate some python code.
answered Jun 6, 2019 at 10:01
PV8PV8
5,5366 gold badges41 silver badges79 bronze badges
Option 1 : Check System Environment Variables > Path
Option 2 : C:UsersAsusAppDataLocalProgramsPython (By default Path)
answered Oct 1, 2022 at 10:09
On my Windows 11, I have two Python installed: 3.11.2 and 3.8. The below commends give only one of them.
Which python
which py
To find out the location of both the below Powershell commands come in handy:
$User = New-Object System.Security.Principal.NTAccount($env:UserName)
$sid = $User.Translate([System.Security.Principal.SecurityIdentifier]).value
New-PSDrive HKU Registry HKEY_USERS
Get-ChildItem "HKU:${sid}SoftwarePythonPythonCore*InstallPath"
answered Mar 27 at 23:26
Иногда нам нужно проверить пакеты или модули по пути, где установлен Python. В этой статье мы покажем три способа, как найти путь, по которому установлен Python в Windows:
- с помощью командной строки
- через меню “Пуск
- используя параметры переменной среды
Итак, давайте начнем!
Примечание редакции: о собственно установке Python читайте в статье “Как установить Python на Windows 10 или 11”.
Чтобы узнать, где установлен Python, используя командную строку Windows, следуйте приведенным ниже примерам.
Пример 1: команда where
Для начала попробуйте использовать команду where
, чтобы вывести путь к директории установленного Python:
>where python
Как видите, в результате нужный путь был найден и отображен в командной строке:
Пример 2: команда py
Команда py
с опцией --list-paths
также может быть использована для перечисления путей к Python:
Как найти место установки Python в Windows с помощью меню “Пуск”
Чтобы найти, где установлен Python, используя меню “Пуск”, выполните следующую процедуру.
Сначала найдите файл “Python.exe” в меню “Пуск”. Затем выберите опцию “Открыть расположение файла”, чтобы открыть соответствующую папку:
В результате вы будете перемещены в каталог, где установлен Python:
Как найти место установки Python в Windows с помощью переменной окружения
Чтобы узнать, где установлен Python, используя переменную окружения PATH
, выполните следующие действия.
Шаг 1. Откройте расширенные системные настройки
Нажмите Window+I, чтобы открыть Настройки системы. Затем выберите “Система” из списка доступных категорий:
Найдите в строке поиска “Дополнительные параметры системы” и откройте их:
Шаг 2. Откройте переменные среды
В Дополнительных параметрах системы нажмите на кнопку “Переменные среды”:
Шаг 3. Откройте переменную среды Path
На вкладке “Системные переменные” выберите “Path” и нажмите кнопку “Изменить” для просмотра сведений о пути:
Из переменной среды Path
можно найти место, где установлен Python, как показано ниже:
Заключение
Узнать, где в Windows установлен Python, можно разными способами, например, с помощью командной строки, меню “Пуск” и системных переменных среды.
Для первого способа откройте командную строку и воспользуйтесь командой where python
. Во втором случае найдите “python.exe” в меню “Пуск” и откройте местоположение файла. При третьем подходе вы можете узнать расположение Python через переменную среды “Path”.
Перевод статьи Rafia Zafar «How Can I Find Where Python is Installed on Windows».
I’m working on a new server for a new workplace, and I’m trying to reuse a CGI script I wrote in Python earlier this year. My CGI script starts off with
#!/local/usr/bin/python
But when I run this on the new server, it complains that there’s no such folder. Obviously Python’s kept in a different place on this box, but I’ve got no idea where.
I haven’t done much unix before, just enough to get around, so if there’s some neat trick I should know here I’d appreciate it 🙂
Thanks!
Josh Lee
169k38 gold badges268 silver badges274 bronze badges
asked Dec 7, 2010 at 4:35
1
Try:
which python
in a terminal.
answered Dec 7, 2010 at 4:37
icyrock.comicyrock.com
27.8k4 gold badges65 silver badges84 bronze badges
1
For this very reason it is recommend that you change your shebang line to be more path agnostic:
#!/usr/bin/env python
See this mailing list message for more information:
Consider the possiblities that in a different machine, python may be installed at
/usr/bin/python
or/bin/python
in those cases,#!/usr/local/bin/python
will fail.
For those cases, we get to call theenv
executable with argument which will determine the arguments path by searching in the$PATH
and use it correctly.(
env
is almost always located in/usr/bin/
so one need not worry thatenv
is not present at/usr/bin
.)
answered Dec 7, 2010 at 4:41
John KugelmanJohn Kugelman
347k67 gold badges524 silver badges574 bronze badges
1
# which python
/usr/local/bin/python
Update:
I misread. Replace your header with
#!/usr/bin/env python
This will pull in the python location from the user that runs the script’s environmental settings
answered Dec 7, 2010 at 4:37
FalmarriFalmarri
47.4k41 gold badges151 silver badges191 bronze badges
Try: which python
or whereis python
answered Dec 7, 2010 at 4:37
SiegeXSiegeX
135k23 gold badges144 silver badges153 bronze badges
It is a good idea to use backticks for header Python script:
`which python`
answered Dec 7, 2010 at 7:30
Yuda PrawiraYuda Prawira
11.9k10 gold badges46 silver badges54 bronze badges
The proper way to solve this problem is with
#!/usr/bin/env python
which allows for the use of a binary in the PATH in a shebang.
answered Dec 7, 2010 at 4:38
Josh LeeJosh Lee
169k38 gold badges268 silver badges274 bronze badges
I have just migrated from Windows environment. I have installed Python 3.2 in a separate directory. How can I get the python installation path in Ubuntu shell?
Is there any way I can let the shell know/choose at runtime which python version is to be used for further code execution?
Are there any environment variables and search path kind of things in Ubuntu Linux as well?
Zanna♦
68.8k55 gold badges214 silver badges326 bronze badges
asked Feb 27, 2013 at 19:11
First question:
which python
though its usually /usr/bin/python
for the 2.7
Second question:
From a terminal & python2.7: python2.7 yourfile.py
.
Simailarly for 3.2: python3.2 yourfile.py
though 3.2 isn’t installed by default. (You can apt-get install python3.2
.)
What python yourfile.py
will do depends on which alternative is used for your python interpreter. You can change that by issuing update-alternatives python
as root
(or by using su
).
Third question:
Environment variables are shell dependent, though you can write them out with echo $variable
and set them with variable=value
(from bash
). The search path is simply called PATH
and you can get yours by typing echo $PATH
.
I hope this was helpful.
answered Feb 27, 2013 at 19:31
WolferWolfer
2,1041 gold badge14 silver badges20 bronze badges
3
If you want to find the location of a program you can just use whereis <program>
.
In your case run:
whereis python2.7
whereis python3.2
For finding every file that apt-get has copied for installation use:
dpkg -S python2.7
dpkg -S python3.2
But maby it is recommend to save it in a textfile, because the output is to large.
dpkg -S python2.7 >log.txt
gedit log.txt
for running .py file with python 3.2
python3.2 <file.py>
answered Feb 27, 2013 at 20:00
Thomas15vThomas15v
1,5931 gold badge11 silver badges21 bronze badges
4
Here is a simple way, run in terminal:
type -a python
or
type -a python3
answered Aug 3, 2019 at 16:55
2
For Python2.7
whereis python2.7
For Python3.2
whereis python3.2
For Python 3.8
which python3
or
whereis python3
answered Aug 6, 2020 at 9:20
2
In the Python interprete, run these two commands:
>>> import sys
>>> sys.path
and one of those outputs will be the installation path
cocomac
2,8823 gold badges15 silver badges44 bronze badges
answered Jul 5, 2022 at 0:25
Добрый день, есть Linux Mint, поставил PyCharm, написал программу. Запускаю из PyCharm – работает.
Запускаю через командную строку python3 test.py – выдает ошибку, не может найти библиотеки.
Как я понимаю есть несколько интерпретаторовокружений.
Как бы мне выяснить с какими параметрами я запускаю в PyCharm и также запустить в командной строке?
-
Вопрос заданболее трёх лет назад
-
54221 просмотр
Пригласить эксперта
попробуйте команду which он укажет где находится исполняемый файл.
Пример:which python3
Ответ: будет примерно/usr/bin/python3
в Window 10 путь к интерпретатору python по-умолчанию можно узнать через команду where python
#держувкурсе
Если создавали проект через PyCharm – то по умолчанию используется venv в папке с проектом.
Чтобы активировать venv из терминала – выполните команду source venv/bin/activate
, находясь при этом в папке с проектом
В PyCharm есть встроенный терминал, вызывается по сочетанию клавиш Alt + F12. В нем venv уже активирован.
В каталоге доустановить библиотеки «в ручную», набрав в консоли: pip install название_библиотеки
-
Показать ещё
Загружается…
24 мая 2023, в 10:23
700 руб./за проект
24 мая 2023, в 10:07
3000 руб./за проект
24 мая 2023, в 09:29
6000 руб./за проект