6

I have an issue that has been discussed in some GitHub blogs but the answers there are so confusing and complex that I thought to ask here as well. Before asking, let me just say I'm not an expert programmer, so my apologizes if mine is a simple question.

  • I recently had to install Python 3.7

  • I used to have modules like clr and System working totally fine and now everything seems broker. I use Anaconda/Spyder to simply load the packages clr and System and Python gives me the following error messages:

    No module named 'clr' No module named 'System'

I managed to fix (apparently) the clr issue by running

pip install clr

from Anaconda Prompt. However, in order to fix the issue with the System module, it seems I need to install pythonnet (I don't knoww exactly what it is but I guess it doesn't matter). Based on anaconda official website: https://anaconda.org/pythonnet/pythonnet I should simply run:

conda install -c pythonnet pythonnet

But that doesn't work. My extremely limited understanding is that something is going wrong between Pythonnet and Python 3.7. Does anybody have a clue of what I should do?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Angelo
  • 1,594
  • 5
  • 17
  • 50

4 Answers4

3

you must uninstall first clr and then do pip install pythonnet. pythonnet has clr and System.

check documentation: https://github.com/pythonnet/pythonnet

  • worked for me. Couldn't find how to "pip install system"... and this did it. Thanks! (note: didn't need to install clr after that) – Ari Oct 18 '21 at 13:31
1

you should use this:

import clr

clr.AddReference('System')

from System import String
betelgeuse
  • 1,136
  • 3
  • 13
  • 25
swordxwind
  • 11
  • 2
  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – MD. RAKIB HASAN Dec 15 '21 at 07:02
1

What eventually worked for me, after messing around with my packages, was to: 1. uninstall clr. 2. Uninstall pythonnet. 3. Only at this point, I had to reinstall pythonnet. This sequence fixed my problem.

pip uninstall clr
pip uninstall pythonnet 
pip install pythonnet 
Angelo
  • 1,594
  • 5
  • 17
  • 50
-1

In my Python3, System is not a module - it's a method of the os module.

so I use

from os import system

then

system("<<Put Your Command Here>>")

If you want it called System with a capital S (maybe for backward compatability with already-written programs?), use

from os import system as System
  • Or you can preserve the name space (which I mostly prefer) and do `import os` and type `os.system(...)` – Ronald Jul 14 '20 at 20:56
  • But that loads the whole of the os module, which is a right waste of memory if only the system method is required. AND even worse, namespace is consumed for everything named within a module, and there could be thousands! So "import os" uses MUCH more namespace than "from os import system" – ExperiMentor Jul 15 '20 at 23:14
  • This answer is not about the question posted. The OP asked about the Windows System DLL to be loaded by pythonnet, not the Python `os.system method.` – Leonardo May 14 '21 at 16:38