为什么 Jupyter Notebook 不从 VBA 运行?

我正在尝试从 Access VBA 运行 Jupyter notebook:


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 分钟,但现在不...


开心每一天1111
浏览 149回答 1
1回答

POPMUISE

弄清楚了。我在其他人需要放置其特定信息的地方放置了方括号:Sub execute_notebook()Dim objShell As ObjectDim new_cmd_window              As StringDim full_script                 As StringDim activate_env                As StringDim change_dir_script           As StringDim convert_and_run_nb          As StringSet 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_scriptEnd Sub关于我的发现的几点说明:没有工作new_cmd_window出于某种原因,简单地使用activate [environment name]VBA 是行不通的。当我将它输入 cmd 行时很好。最后我不得不手动更改目录并以这种方式运行它。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python