【问题标题】:Pythonnet error: dynamic module not initialized properlyPythonnet 错误:动态模块未正确初始化
【发布时间】:2016-01-20 20:45:09
【问题描述】:

我在 win32 上安装了 Windows 7 x64 和 Python 2.7.6 版。 安装的框架是:

Microsoft .NET 框架 4.5.2 Microsoft .NET Framework 4 多目标包。 所以,当我运行我的应用程序时,他崩溃了:

import clr

出现此错误:

SystemError: dynamic module not initialized properly

我也用 Visual C# 2010 express 重建了 pythonnet,使用 x86 平台,但没有。

谁能帮帮我,拜托。 可能任何人都可以告诉我安装使用 pythonnet 所需的 .NET Framework。

【问题讨论】:

标签: python .net python.net


【解决方案1】:

我也有这种行为。我通过 pip 安装 Python.net 来修复它:

python -m pip install pythonnet(可能需要以管理员/root 身份运行)

安装完成后执行时不会出现任何错误

> python
> import clr

【讨论】:

    【解决方案2】:

    发生错误是因为您的clr.pyd 找不到Python.Runtime.dll。基本上您已经成功导入clr.pyd,但是您的clr.pyd 找不到Python.runtime.dll。因此,为了使您的 dll 可搜索,您需要将 Python.Runtime.dll 的位置添加到 System PATH 中。

    假设您的main.py 其中import clr 和您的clr.pydPython.Runtime.dll 在同一个目录中,您只需在main.py 的开头添加以下几行:

    import sys
    import os
    
    sys.path.insert(0, os.path.abspath('./')) # add the current file location to sys path so that the clr module is searchable
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 2017-06-06
      • 2023-03-12
      • 2016-02-05
      • 2015-03-18
      相关资源
      最近更新 更多