Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
480 views
in Technique[技术] by (71.8m points)

c# - How to install Python for .NET on Windows

I downloaded Python for .NET.
Inside the zip is clr.pyd, nPython.exe, Python.Runtime.dll and 2 debug database files.
I put the clr.pyd and Python.Runtime.dll in my python DLLs dir C:Python27DLLs thinking this is all that's needed for installation. I then open up the Python GUI and type import clr and I get:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    import clr
SystemError: dynamic module not initialized properly

New to python but not .NET and want to use the CPython and not IronPython. What am I missing in this installation? The readme of Python for .NET says there is an installation for Windows package but all I found was the zip file.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The proper way to load CLR in Python is like this:

  1. Make sure no old stuff is left from Python.NET in Python installation folder (e.g. C:Python27). In my case I had legacy clr.pyd in one of folders. Note that pip for some old versions did not remove all parts of Python.NET.
  2. Append the directory with Python.NET files (clr.pyd and Python.Runtime.dll) to sys.path

Now you can load CLR the most flexible way without even installing to Python directories!

You can compile from source on github:

pip install git+https://github.com/pythonnet/pythonnet

or use Windows wheels/installers from Christoph Gohlke:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonnet

PyPI package is available for installation from pip:

https://pypi.python.org/pypi/pythonnet

More installation options such docker, WinPython, conda, nuget, choco are listed here:

https://github.com/pythonnet/pythonnet/wiki/Installation


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...