vincenzo gisondi
vincenzo gisondi

Reputation: 61

Pythonnet error: dynamic module not initialized properly

I have Windows 7 x64 and a Python version 2.7.6 on win32. The framework installed are:

Microsoft .NET Framework 4.5.2 Microsoft .NET Framework 4 Multi-Targeting Pack. So, when I run my application he crashs on:

import clr

with this error:

SystemError: dynamic module not initialized properly

I have also rebuild pythonnet with Visual C# 2010 express, with x86 platform, but nothing.

Can anyone help me, please. And possibly can anyone tell me the required .NET Framework installed for use pythonnet.

Upvotes: 4

Views: 6398

Answers (2)

MaThMaX
MaThMaX

Reputation: 2015

The error happens because of that your clr.pyd cannot find the Python.Runtime.dll. Basically You have already import the clr.pyd successfully, but Your the clr.pyd cannot find the Python.runtime.dll. So in order to make your dll searchable, you need to add the location of your Python.Runtime.dll into the System PATH.

Let's say you have your main.py which import clr and your clr.pyd and Python.Runtime.dll in the same directory, you will just need to add the below few lines at the beginning of your 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

Upvotes: 1

Arnold Pistorius
Arnold Pistorius

Reputation: 532

I had this behavior too. I fixed it by installing Python.net via pip:

python -m pip install pythonnet (might need to run as Administrator/root)

After installation completes you should not get any error when executing

> python
> import clr

Upvotes: 2

Related Questions