【问题标题】:Why isn't Jupyter notebook running from VBA?为什么 Jupyter notebook 不从 VBA 运行?
【发布时间】:2020-06-29 12:24:19
【问题描述】:

我正在尝试从 Access VBA 运行 Jupyter 笔记本:

Sub import_hawk()

Dim objShell As Object
Dim PythonExe, PythonScript As String

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

    PythonExe = """C:\Users\Philip\.conda\envs\latest\python.exe"""
    PythonScript = "C:\Users\Philip\OneDrive\Betting\Capra\Tennis\polgara\polgara.ipynb"

    objShell.run PythonExe & PythonScript

End Sub

当我运行它时,一个框会短暂出现然后消失。我已经手动运行了笔记本,它工作正常。最令人沮丧的是,它工作了大约 5 分钟,现在不行了……

【问题讨论】:

  • 你不应该用jupyter notebook <notebook> 运行笔记本吗?
  • 您也没有在 PythonExe 和 PythonScript 之间提供空格
  • @michalwa - 恐怕我在这方面还很陌生 - VBA 中的哪个位置?
  • @ErikA - 添加空间无济于事:(
  • 将python的路径替换为jupyter notebook ,其中jupyter可以替换为jupyter的完整路径。

标签: python vba ms-access jupyter-notebook


【解决方案1】:

想通了。我已将方括号放在其他人需要放置其特定信息的位置:

Sub execute_notebook()

Dim objShell As Object
Dim new_cmd_window              As String
Dim full_script                 As String
Dim activate_env                As String
Dim change_dir_script           As String
Dim convert_and_run_nb          As String

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

new_cmd_window = "cmd /c"
activate_env = "cd /d [path to Anaconda\Scripts folder which on my machine is C:\ProgramData\Anaconda3\Scripts] & activate [environment_name] &"
change_dir_notebook = "cd /d [path to folder where notebook is] &"
convert_and_run_nb = "jupyter nbconvert --to notebook --execute [notebook name].ipynb"
full_script = new_cmd_window & " " & Chr(34) & activate_env & " " & change_dir_script & " " & convert_and_run_nb & Chr(34)

objShell.run full_script

End Sub

关于我的发现的几点说明:

  1. 没有new_cmd_window 就无法工作
  2. 出于某种原因,简单地使用activate [environment name] 在VBA 中不起作用。当我将它输入到 cmd 行时很好。最后我不得不手动更改目录并以这种方式运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-21
    • 1970-01-01
    相关资源
    最近更新 更多