# No module named 'clr' error

**URL:** <https://discourse.slicer.org/t/no-module-named-clr-error/22028>\
**Category:** Support\
**Created:** [February 17, 2022, 6:44pm UTC](https://discourse.slicer.org/t/no-module-named-clr-error/22028 "2022-02-17T18:44:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![siaeleni](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@siaeleni](https://discourse.slicer.org/u/siaeleni)\
**Post date:** [February 17, 2022, 6:44pm UTC](https://discourse.slicer.org/t/no-module-named-clr-error/22028/1 "2022-02-17T18:44:53Z")

</div>

Hello,  
I use a module and I get the following error when they try to import clr:  
“No module named ‘clr’ error”  
I tried to import pythonnet by using: pip\_install(‘pythonnet’).  
But when I restart 3DSlicer I get the following pop up and  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/a/0a787b0048be2b79967523f1205663a131967694.png)

Any idea that can be helful?  
Thank you

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [February 17, 2022, 8:20pm UTC](https://discourse.slicer.org/t/no-module-named-clr-error/22028/2 "2022-02-17T20:20:51Z")

</div>

Does installing `pythonnet` in a system python (not Python integrated into Slicer) such as Python 3.9.10 work for you? Do you have the same import error?

Slicer uses an integrated Python 3.9.10, but pypi says there is not an available whl for this python package for Python 3.9 ([pythonnet · PyPI](https://pypi.org/project/pythonnet/2.5.2/#files)) so it’s likely trying to build from source which can open you up to many errors if you don’t have all the required build tools.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 18, 2022, 1:24am UTC](https://discourse.slicer.org/t/no-module-named-clr-error/22028/3 "2022-02-18T01:24:13Z")

</div>

See the answer to this question in the pythonnet issue tracker:

> <https://github.com/pythonnet/pythonnet/issues/1647#issuecomment-1001495228>
>
> \### Environment
> 
> \- Pythonnet version: 2.5.2
> \- Python version: 3.9
> \- Op…erating System: macosx 11.6
> \- .NET Runtime:
> 
> \### Details
> 
> \- pip3 install pythonnet==2.5.2 crashes with error. I see the 2.5.2 does support python 3.9, was wondering why it crashes on pip3 install. 
> 
> \_TODO\_
> 
> \- What commands did you run to trigger this issue? If you can provide a
> \[Minimal, Complete, and Verifiable example\](http://stackoverflow.com/help/mcve)
> this will help us understand the issue.
> 
> \`\`\`python
> print('TODO')
> \`\`\`
> 
> \- Collecting pythonnet==2.5.2
> Downloading pythonnet-2.5.2.tar.gz (1.9 MB)
> |████████████████████████████████| 1.9 MB 851 kB/s            
> Preparing metadata (setup.py) ... done
> Collecting pycparser
> Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
> |████████████████████████████████| 118 kB 148 kB/s            
> Building wheels for collected packages: pythonnet
> Building wheel for pythonnet (setup.py) ... error
> ERROR: Command errored out with exit status 1:
> command: /Users/apoudel/Desktop/hpc\_lib/homebrew/opt/python@3.9/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv\[0\] = '"'"'/private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-install-sj3whon9/pythonnet\_99c95ae1c8dc44df9dc8586a2f7ee189/setup.py'"'"'; \_\_file\_\_='"'"'/private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-install-sj3whon9/pythonnet\_99c95ae1c8dc44df9dc8586a2f7ee189/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(\_\_file\_\_) if os.path.exists(\_\_file\_\_) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\\r\\n'"'"', '"'"'\\n'"'"');f.close();exec(compile(code, \_\_file\_\_, '"'"'exec'"'"'))' bdist\_wheel -d /private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-wheel-2wbatvmt
> cwd: /private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-install-sj3whon9/pythonnet\_99c95ae1c8dc44df9dc8586a2f7ee189/
> Complete output (43 lines):
> running bdist\_wheel
> running build
> running build\_ext
> /bin/sh: mono: command not found
> Traceback (most recent call last):
> File "\<string\>", line 1, in \<module\>
> File "/private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-install-sj3whon9/pythonnet\_99c95ae1c8dc44df9dc8586a2f7ee189/setup.py", line 630, in \<module\>
> setup(
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/lib/python3.9/site-packages/setuptools/\_\_init\_\_.py", line 159, in setup
> return distutils.core.setup(\*\*attrs)
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py", line 148, in setup
> dist.run\_commands()
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 966, in run\_commands
> self.run\_command(cmd)
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run\_command
> cmd\_obj.run()
> File "/private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-install-sj3whon9/pythonnet\_99c95ae1c8dc44df9dc8586a2f7ee189/setup.py", line 612, in run
> return bdist\_wheel.bdist\_wheel.run(self)
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/lib/python3.9/site-packages/wheel/bdist\_wheel.py", line 299, in run
> self.run\_command('build')
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/cmd.py", line 313, in run\_command
> self.distribution.run\_command(command)
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run\_command
> cmd\_obj.run()
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/build.py", line 135, in run
> self.run\_command(cmd\_name)
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/cmd.py", line 313, in run\_command
> self.distribution.run\_command(command)
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run\_command
> cmd\_obj.run()
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/build\_ext.py", line 340, in run
> self.build\_extensions()
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/build\_ext.py", line 449, in build\_extensions
> self.\_build\_extensions\_serial()
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/command/build\_ext.py", line 474, in \_build\_extensions\_serial
> self.build\_extension(ext)
> File "/private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-install-sj3whon9/pythonnet\_99c95ae1c8dc44df9dc8586a2f7ee189/setup.py", line 249, in build\_extension
> self.\_install\_packages()
> File "/private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-install-sj3whon9/pythonnet\_99c95ae1c8dc44df9dc8586a2f7ee189/setup.py", line 438, in \_install\_packages
> subprocess.check\_call(cmd, shell=use\_shell)
> File "/Users/apoudel/Desktop/hpc\_lib/homebrew/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 373, in check\_call
> raise CalledProcessError(retcode, cmd)
> subprocess.CalledProcessError: Command 'mono tools/nuget/nuget.exe update -self' returned non-zero exit status 127.
> ----------------------------------------
> ERROR: Failed building wheel for pythonnet
> Running setup.py clean for pythonnet
> Failed to build pythonnet
> Installing collected packages: pycparser, pythonnet
> DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
> Running setup.py install for pythonnet ... error
> ERROR: Command errored out with exit status 1:
> command: /Users/apoudel/Desktop/hpc\_lib/homebrew/opt/python@3.9/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv\[0\] = '"'"'/private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-install-sj3whon9/pythonnet\_99c95ae1c8dc44df9dc8586a2f7ee189/setup.py'"'"'; \_\_file\_\_='"'"'/private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-install-sj3whon9/pythonnet\_99c95ae1c8dc44df9dc8586a2f7ee189/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(\_\_file\_\_) if os.path.exists(\_\_file\_\_) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\\r\\n'"'"', '"'"'\\n'"'"');f.close();exec(compile(code, \_\_file\_\_, '"'"'exec'"'"'))' install --record /private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-record-rytd6lqg/install-record.txt --single-version-externally-managed --compile --install-headers /Users/apoudel/Desktop/hpc\_lib/homebrew/include/python3.9/pythonnet
> cwd: /private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-install-sj3whon9/pythonnet\_99c95ae1c8dc44df9dc8586a2f7ee189/
> Complete output (6 lines):
> usage: setup.py \[global\_opts\] cmd1 \[cmd1\_opts\] \[cmd2 \[cmd2\_opts\] ...\]
> or: setup.py --help \[cmd1 cmd2 ...\]
> or: setup.py --help-commands
> or: setup.py cmd --help
>     
> error: option --single-version-externally-managed not recognized
> ----------------------------------------
> ERROR: Command errored out with exit status 1: /Users/apoudel/Desktop/hpc\_lib/homebrew/opt/python@3.9/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv\[0\] = '"'"'/private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-install-sj3whon9/pythonnet\_99c95ae1c8dc44df9dc8586a2f7ee189/setup.py'"'"'; \_\_file\_\_='"'"'/private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-install-sj3whon9/pythonnet\_99c95ae1c8dc44df9dc8586a2f7ee189/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(\_\_file\_\_) if os.path.exists(\_\_file\_\_) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\\r\\n'"'"', '"'"'\\n'"'"');f.close();exec(compile(code, \_\_file\_\_, '"'"'exec'"'"'))' install --record /private/var/folders/95/c\_bn57x5613fwcs5n60rckzw0000gp/T/pip-record-rytd6lqg/install-record.txt --single-version-externally-managed --compile --install-headers /Users/apoudel/Desktop/hpc\_lib/homebrew/include/python3.9/pythonnet Check the logs for full command output.
> 
> \`\`\`python
> print('TODO')
> \`\`\`
> I would really appreciate if someone could help me resolve this error. Thanks!

---

<div class="post-metadata">

**Author:** ![siaeleni](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@siaeleni](https://discourse.slicer.org/u/siaeleni)\
**Post date:** [February 18, 2022, 3:27am UTC](https://discourse.slicer.org/t/no-module-named-clr-error/22028/4 "2022-02-18T03:27:34Z")

</div>

Thanks for the answer.  
I installed the --pre pythonnet in Slicer 4.13, but seems that I get the same error:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/8/68661a2c151df7b7954f090203358de167360cd6.png)

Also, I checked the PYTHONPATH and I get the following:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/8/088d5fd0f3664176baa2f2aaaacd0842f7c693ac.png)

Thanks for your help,  
Eleni

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 18, 2022, 4:02am UTC](https://discourse.slicer.org/t/no-module-named-clr-error/22028/5 "2022-02-18T04:02:01Z")

</div>

I’ve tested pythonnet with latest Slicer Preview Release on Windows, installed using

```python
pip_install('--pre pythonnet')

```

Everything seems to work well. Your problem most likely is not related to pythonnet.

A software component overwriting PYTHONPATH would be completely unacceptable, and announcing this in a popup called “Delete Files” makes things even more bizarre. I would recommend to contact the developers of the code that displays this message to sort this out. If they cannot make their software compatible without such a huge hack then I would recommend not to try to integrate it directly with Slicer, but instead send data to Slicer via OpenIGTLink, using [pyigtl](https://pypi.org/project/pyigtl/).

---

<div class="post-metadata">

**Author:** ![siaeleni](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@siaeleni](https://discourse.slicer.org/u/siaeleni)\
**Post date:** [February 21, 2022, 4:02am UTC](https://discourse.slicer.org/t/no-module-named-clr-error/22028/6 "2022-02-21T04:02:02Z")

</div>

Yes, you are right, the problem is coming from that package that I was using.  
I could reproduce it on their side as well. Thanks for your help
