No module named 'System'

Viewed 7634

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?

4 Answers

you should use this:

import clr

clr.AddReference('System')

from System import String

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 

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
Related