# module 'importlib' has no attribute 'find\_spec'

**URL:** <https://community.mrtrix.org/t/module-importlib-has-no-attribute-find-spec/7833>\
**Category:** Uncategorized\
**Created:** [July 26, 2024, 12:38pm UTC](https://community.mrtrix.org/t/module-importlib-has-no-attribute-find-spec/7833 "2024-07-26T12:38:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cabellotoscano](https://community.mrtrix.org/user_avatar/community.mrtrix.org/cabellotoscano/32/4857_2.png) [@cabellotoscano](https://community.mrtrix.org/u/cabellotoscano)\
**Post date:** [July 26, 2024, 12:38pm UTC](https://community.mrtrix.org/t/module-importlib-has-no-attribute-find-spec/7833/1 "2024-07-26T12:38:26Z")

</div>

I think I correctly installed mrtrix3 with anaconda on my ubuntu server. I did it both in a envirnomnet with python version 3.12.4 and in another environment with python 2.7.18

When I do 5ttgen in the python3 environment I receive:

```auto
(base) mariacabello@neuroworki:~/Desktop$ 5ttgen
Traceback (most recent call last):
  File "/home/mariacabello/anaconda3/bin/5ttgen", line 69, in <module>
    import mrtrix3
  File "/home/mariacabello/anaconda3/bin/mrtrix3.py", line 38, in <module>
    if not imported (os.path.normpath (os.path.join ( \
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mariacabello/anaconda3/bin/mrtrix3.py", line 25, in imported
    fp, pathname, description = imp.find_spec('mrtrix3', [lib_path])
                                ^^^^^^^^^^^^^
AttributeError: module 'importlib' has no attribute 'find_spec'

```

When I do 5ttgen in the python2 environment I receive:

```auto
(py27) mariacabello@neuroworki:~/Desktop$ 5ttgen
Traceback (most recent call last):
  File "/home/mariacabello/anaconda3/envs/py27/bin/5ttgen", line 69, in <module>
    import mrtrix3
  File "/home/mariacabello/anaconda3/envs/py27/bin/mrtrix3.py", line 39, in <module>
    os.path.dirname (os.path.realpath ( __file__ )), os.pardir, 'lib') )):
  File "/home/mariacabello/anaconda3/envs/py27/bin/mrtrix3.py", line 25, in imported
    fp, pathname, description = imp.find_spec('mrtrix3', [lib_path])
AttributeError: 'module' object has no attribute 'find_spec'

```

Please help

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [July 29, 2024, 12:53am UTC](https://community.mrtrix.org/t/module-importlib-has-no-attribute-find-spec/7833/2 "2024-07-29T00:53:41Z")

</div>

Hi Maria,

The Python 3.12 update seems to have broken a couple of things. Chaning your environment to 3.11 should resolve.  
I’m a little surprised that Python2 doesn’t work, given we’ve invested efforts to this point in preserving compatibility. But it is now officially deprecated, and we will be dropping Python2 support in MRtrix 3.1.

> <https://github.com/MRtrix3/mrtrix3/issues/2947>
>
> Over and above the adoption on \`pathlib\` on \`dev\` that is causing issues on Pyth…on 3.12 (#2931), it seems that 3.12 is also causing issues on \`master\`.
> 
> \[Community forum post\](https://community.mrtrix.org/t/module-importlib-has-no-attribute-find-spec/7833). Also had a second report of \`imp\` not being found, though that's only used as a backup after \`importlib\` fails, so I would have thought that the error message would reflect such.

Rob

---

<div class="post-metadata">

**Author:** ![cabellotoscano](https://community.mrtrix.org/user_avatar/community.mrtrix.org/cabellotoscano/32/4857_2.png) [@cabellotoscano](https://community.mrtrix.org/u/cabellotoscano)\
**Post date:** [July 29, 2024, 6:05am UTC](https://community.mrtrix.org/t/module-importlib-has-no-attribute-find-spec/7833/3 "2024-07-29T06:05:35Z")

</div>

Hi Rob,

Thanks for your answer.

I did:

```auto
conda create -n "python311" python=3.11 ipython
conda activate python311
conda install -c mrtrix3 mrtrix3
5ttgen

```

and I am still getting this for the last line:

```auto
(python311) mariacabello@neuroworki:~/Desktop$ 5ttgen
Traceback (most recent call last):
  File "/home/mariacabello/anaconda3/envs/python311/bin/5ttgen", line 69, in <module>
    import mrtrix3
  File "/home/mariacabello/anaconda3/envs/python311/bin/mrtrix3.py", line 38, in <module>
    if not imported (os.path.normpath (os.path.join ( \
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mariacabello/anaconda3/envs/python311/bin/mrtrix3.py", line 25, in imported
    fp, pathname, description = imp.find_spec('mrtrix3', [lib_path])
                                ^^^^^^^^^^^^^
AttributeError: module 'importlib' has no attribute 'find_spec'

```

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [July 29, 2024, 9:34am UTC](https://community.mrtrix.org/t/module-importlib-has-no-attribute-find-spec/7833/4 "2024-07-29T09:34:48Z")

</div>

`imp` was [removed in 3.12](https://docs.python.org/3/whatsnew/3.12.html#imp), but [still present in 3.11](https://docs.python.org/3.11/library/imp.html).

From this part of the traceback:

```auto
  File "/home/mariacabello/anaconda3/envs/python311/bin/mrtrix3.py", line 25, in imported
    fp, pathname, description = imp.find_spec('mrtrix3', [lib_path])
                                ^^^^^^^^^^^^^

```

, not only is it reporting an absence of that function in the `importlib` rather than `imp` module, but that [doesn’t correspond to the source code at the latest tag](https://github.com/MRtrix3/mrtrix3/blob/3.0.4/bin/mrtrix3.py#L24). Are you attempting to install a version of MRtrix3 other than the latest one, and have you performed any local code edits?

Notably, this code has been [modified on `master`](https://github.com/MRtrix3/mrtrix3/commit/c00b3b82d6fc66af9f4ae7d7a4cf2dd2c8428cf0#diff-affc96de4e97bf2ba13cf26132fce34f53aefb51fea884288a6a92a2d77b0b7eR26-R33) via [#2735](https://github.com/MRtrix3/mrtrix3/pull/2735) due to prior [flagging of `imp` deprecation in #2731](https://github.com/MRtrix3/mrtrix3/issues/2731), but this has not yet made its way to a tag update. So if we were to create a 3.0.5 it might resolve at least this part; but there are other Python 3.12 issues not yet resolved.
