Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA can';t在新电脑上运行python脚本_Python_Vba - Fatal编程技术网

VBA can';t在新电脑上运行python脚本

VBA can';t在新电脑上运行python脚本,python,vba,Python,Vba,这段代码从VBA启动python脚本,在我的旧电脑上运行良好 Sub py_launcher_8() Dim wsh As Object Set wsh = VBA.CreateObject("WScript.Shell") Dim waitOnReturn As Boolean: waitOnReturn = True Dim windowStyle As Integer: windowStyle = 1 Dim errorCode As Lon

这段代码从VBA启动python脚本,在我的旧电脑上运行良好

    Sub py_launcher_8()
    Dim wsh As Object
    Set wsh = VBA.CreateObject("WScript.Shell")
    Dim waitOnReturn As Boolean: waitOnReturn = True
    Dim windowStyle As Integer: windowStyle = 1
    Dim errorCode As Long

        errorCode = wsh.Run("C:/Users/belose/PycharmProjects/week2/venv/Scripts/python.exe" & " " & "C:\Users\belose\PycharmProjects\week2\VGM\VGM_eval.py", windowStyle, waitOnReturn)

        If errorCode = 0 Then
            MsgBox "Done! No error to report."
        Else
            MsgBox "Program exited with error code " & errorCode & "."
        End If
    End Sub
然后我不得不转移到另一台PC上,python位于anaconda环境中:C:\Users\belose\AppData\Local\Continuum\anaconda3\python.exe

    Sub py_launcher_8()
    Dim wsh As Object
    Set wsh = VBA.CreateObject("WScript.Shell")
    Dim waitOnReturn As Boolean: waitOnReturn = True
    Dim windowStyle As Integer: windowStyle = 1
    Dim errorCode As Long

        errorCode = wsh.Run("C:\Users\belose\AppData\Local\Continuum\anaconda3\python.exe" & " " & "C:\Users\belose\PycharmProjects\DRM\venv\VGM\VGM_eval.py", windowStyle, waitOnReturn)

        If errorCode = 0 Then
            MsgBox "Done! No error to report."
        Else
            MsgBox "Program exited with error code " & errorCode & "."
        End If
    End Sub
VBA现在不会启动python脚本并返回错误代码1

python脚本本身是正常的


原因可能是什么?

我建议您使用
print(“Hello World..!!”)
编写一个
test.py
脚本,并运行它来检查问题是否是由于
python.exe的路径
或执行
python脚本
造成的

如果它正在运行,那么您应该检查python脚本,如果没有,那么您应该验证
python.exe
路径

要定位python路径,可以使用以下步骤:

  • 从“开始”菜单中打开
    蟒蛇提示
  • 如果您想要conda环境中Python解释器的位置,而不是 根conda环境,运行
    激活环境名称
  • 运行
    where python

  • 事实证明,环境中缺少一些库。谢谢