为了账号安全,请及时绑定邮箱和手机立即绑定

为什么 Jupyter Notebook 不从 VBA 运行?

为什么 Jupyter Notebook 不从 VBA 运行?

开心每一天1111 2023-02-07 14:25:18
我正在尝试从 Access VBA 运行 Jupyter notebook:Sub import_hawk()Dim objShell As ObjectDim 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 & PythonScriptEnd Sub当我运行它时,一个框会短暂出现然后消失。我已经手动运行笔记本并且工作正常。最令人沮丧的是,它工作了大约 5 分钟,但现在不...
查看完整描述

1 回答

?
POPMUISE

TA贡献1765条经验 获得超5个赞

弄清楚了。我在其他人需要放置其特定信息的地方放置了方括号:


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 行时很好。最后我不得不手动更改目录并以这种方式运行它。



查看完整回答
反对 回复 2023-02-07
  • 1 回答
  • 0 关注
  • 120 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号