cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2897
Views
3
Helpful
6
Replies

acitoolkit ImportError - cannot import 'Sequence' from 'collections'

EAG
Level 1
Level 1

Hello all,

I am having an ImportError issue using acitoolkit on Python.

I already installed the acitoolkit package with 'pip install acitoolkit' command from bash terminal within Pycharm (on Ubuntu Linux ssytem), but it is giving me an ImportError at the code below.

My code on Pycharm environment:

from acitoolkit.acitoolkit import *        # This imports the acitoolkit module from the acitoolkit package

 

The output:

from acitoolkit.acitoolkit import * # This imports the acitoolkit module from the acitoolkit package
File "/usr/local/lib/python3.10/dist-packages/acitoolkit/__init__.py", line 35, in <module>
from .acitoolkit import ( # noqa
File "/usr/local/lib/python3.10/dist-packages/acitoolkit/acitoolkit.py", line 33, in <module>
from collections import Sequence
ImportError: cannot import name 'Sequence' from 'collections' (/usr/lib/python3.10/collections/__init__.py)

 

I'd be glad if I can receive advice on how to rectify this.

Thanks all.

2 Accepted Solutions

Accepted Solutions

@EAG i think its the python version you are using, is 3.10 supported with ACI toolkit? There is a number of issues on the repo for versions 3.x.

Try

import importlib

sequence_module = importlib.import_module('collections')
Sequence = getattr(sequence_module, 'Sequence')

or import all the names from the acktoolkit.acitoolkit module. If this fails with an error that contains the string cannot import name "Sequence", then the code imports the Sequence class from the typing module instead. Then, the code raises the original error.

try:
    from acktoolkit.acitoolkit import *
except ImportError as e:
    if 'cannot import name "Sequence"' in str(e):
        # The Sequence class is deprecated
        from typing import Sequence
    else:
        # Another error occurred
        raise

I am still thinking its a version issues, i would raise this on the repo too if you have not already https://github.com/datacenter/acitoolkit - however.... i do not know if this is still being maintained?

Funny i typed out all of the above and was also looking at issues and saw this https://github.com/datacenter/acitoolkit/issues/380

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

View solution in original post

EAG
Level 1
Level 1

Hi @bigevilbeard, thanks for the assistance.

I guess you were right as par the Python version. Was finally able to find my way around using the 2 links from github you suggested. 

Had to do some tweaking of of the source file of the acitoolkit.py file within the acitoolkit package installed on my system.

Thanks again for the assistance.

View solution in original post

6 Replies 6

Marcel Zehnder
Spotlight
Spotlight

Hi 
Try to replace import * with the stuff you need in your script, for example:
instead of: 

from acitoolkit.acitoolkit import *


do:

 

from acitoolkit.acitoolkit import Session
from acitoolkit.aciphysobject import Pod, Node, Link

 

 

Hi Marcel,

Tried that, still giving the same thing. Don't know why

@EAG Looks like the error message you are getting is because the Sequence class has been moved from the collections module to the typing module in Python 3.10. The collections module still contains the Sequence class, but it is now deprecated in Python 3.10. The typing module is the preferred way to import the Sequence class in Python 3.10.

Try....

 

from acitoolkit.acitoolkit import *
from typing import Sequence

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Hello @bigevilbeard,

Thanks for the suggestions,  

Yeah, but how do I find my way around the fact that the Sequence class, though deprecated is still within the collections s module? Your code still has the line 'from acktoolkit.acitoolkit import *' which is causing the import error. Putting it after the next import line still results on an error, as long as the collections module still contains the Sequece class. I even tried using exceptions to deal with this but then it jumped the entire import of the acitoolkit.acitoolkit module.

@EAG i think its the python version you are using, is 3.10 supported with ACI toolkit? There is a number of issues on the repo for versions 3.x.

Try

import importlib

sequence_module = importlib.import_module('collections')
Sequence = getattr(sequence_module, 'Sequence')

or import all the names from the acktoolkit.acitoolkit module. If this fails with an error that contains the string cannot import name "Sequence", then the code imports the Sequence class from the typing module instead. Then, the code raises the original error.

try:
    from acktoolkit.acitoolkit import *
except ImportError as e:
    if 'cannot import name "Sequence"' in str(e):
        # The Sequence class is deprecated
        from typing import Sequence
    else:
        # Another error occurred
        raise

I am still thinking its a version issues, i would raise this on the repo too if you have not already https://github.com/datacenter/acitoolkit - however.... i do not know if this is still being maintained?

Funny i typed out all of the above and was also looking at issues and saw this https://github.com/datacenter/acitoolkit/issues/380

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

EAG
Level 1
Level 1

Hi @bigevilbeard, thanks for the assistance.

I guess you were right as par the Python version. Was finally able to find my way around using the 2 links from github you suggested. 

Had to do some tweaking of of the source file of the acitoolkit.py file within the acitoolkit package installed on my system.

Thanks again for the assistance.