PythonNet FileNotFoundException:无法找到程序集 [英] PythonNet FileNotFoundException: Unable to find assembly

查看:557
本文介绍了PythonNet FileNotFoundException:无法找到程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行将Python用于.Net的Python脚本( https://github.com/pythonnet / pythonnet )加载名为 Kratos_3.dll的C#库,该库与脚本位于同一文件夹中,但找不到该文件。

I am trying to execute a Python script that uses Python For .Net (https://github.com/pythonnet/pythonnet) to load a C# library called "Kratos_3.dll" which is in the same folder as the script but the file cannot be found.

我已经使用 pip install pythonnet安装了clr。

I have installed clr using "pip install pythonnet".

这是我的脚本:

import clr
import sys
sys.path.insert(0,"C:\\dev\\proj_1\\")
clr.AddReference("Kratos_3") 

我不断收到错误消息

FileNotFoundException: Unable to find assembly 'Kratos_3. at Python.Runtime.CLRModule.AddReference(String name)

使用IronPython运行它时,但是我想使用常规Python 2.7来使它工作,我该怎么办?

When I run this using IronPython it works, but I would like to get this to work using regular Python 2.7, what do I need to do?

推荐答案

事实证明,即使我添加了通过

It turns out that even though I added the path through

sys.path.insert(0,"C:\\dev\\proj_1\\")

它仍然找不到文件,因为.dll是因为Windows无法使它从外部来源加载。要解决此问题:

it still couldn't find the file because the .dll because Windows was not enabling it to load from "external sources". To fix this:


  1. 右键单击.dll

  2. 属性

  3. 在常规下,单击取消阻止

这篇关于PythonNet FileNotFoundException:无法找到程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆