简体   繁体   English

如何从cmd获取python.exe路径?

[英]How to get python.exe path from cmd?

I have two pythons installed to my computer.我的电脑上安装了两个 python。 One is a separate version, another is a part of Anaconda package.一个是单独的版本,另一个是 Anaconda 包的一部分。 I use the one which comes with Anaconda (I use Spyder to run it), because the other one doesn't have win32api and so on.我使用 Anaconda 附带的一个(我使用 Spyder 来运行它),因为另一个没有 win32api 等等。

I need to find out the location of python.exe that Spyder is using when it runs the script.我需要找出 Spyder 在运行脚本时使用的 python.exe 的位置。

My aim is to run the py script from excel VBA using the code:我的目标是使用以下代码从 excel VBA 运行 py 脚本:

Sub RunPython()

Dim objShell As Object
Dim PythonExe, PythonScript As String

Set objShell = VBA.CreateObject("Wscript.Shell")

PythonExe = """C:\Users\EEEEEEEEEEEEE\AppData\Local\Continuum\anaconda3\lib\os.py"""
PythonScript = """//fileh01/home$/EEEEEEEEEEEEE/Desktop/Python/test.py"""

objShell.Run PythonExe & PythonScript

End Sub

If I go to anaconda prompt and type python //fileh01/home$/EEEEEEEEEEEEE/Desktop/Python/test.py everything works.如果我转到 anaconda 提示符并键入python //fileh01/home$/EEEEEEEEEEEEE/Desktop/Python/test.py一切正常。 But when I run code from VBA, nothing happens.但是当我从 VBA 运行代码时,没有任何反应。

In either cmd or the Anaconda prompt, You can find the location of your Python.exe using:在 cmd 或 Anaconda 提示符下,您可以使用以下命令找到 Python.exe 的位置:

where python

You could also try:你也可以试试:

where anaconda

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM