08-13-2023 03:44 PM
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.
Solved! Go to Solution.
08-17-2023 02:35 AM
@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
08-19-2023 06:05 PM - edited 08-19-2023 06:09 PM
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.
08-13-2023 11:16 PM - edited 08-13-2023 11:17 PM
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
08-14-2023 07:25 AM
Hi Marcel,
Tried that, still giving the same thing. Don't know why
08-14-2023 08:52 AM
@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
08-16-2023 05:32 PM
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.
08-17-2023 02:35 AM
@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
08-19-2023 06:05 PM - edited 08-19-2023 06:09 PM
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.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide