gpt4 book ai didi

python - ipython 笔记本和脚本的区别 - 加载 DLL

转载 作者:太空宇宙 更新时间:2023-11-03 17:26:42 24 4
gpt4 key购买 nike

有人注意到 IPython/Jupyter Notebook/(qt)console 和使用 pythonnet 的普通 Python 脚本加载 .NET dll 之间的差异吗?

这是 pythonnet 或 ipython 端引起的错误/行为吗?

这适用于 ipython 和 python 交互式控制台:

import clr
clr.AddReference(r"C:\path2dll\dotnetdll")

但在常规 python 脚本中,sys.path 必须附加 DLL 的路径:

import clr
import sys
sys.path.append(r"C:\path2dll")
clr.AddReference("dotnetdll")

可能类似的问题:

Permission denied on dl.open() with ipython but not with python

最佳答案

在交互模式下,Python 解释器将空字符串 "" 附加到 sys.path。作为此问题的副作用,pythonnet 中存在缺陷的 AssemblyManager 仅在解释器模式下从完整路径加载程序集。

关于python - ipython 笔记本和脚本的区别 - 加载 DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32465864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com