cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
284
Views
0
Helpful
4
Replies

Cisco Python library import is not working

Hello guys,

Upon enabling the NPV feature on my Cisco switch I found an error,

I have no idea if this is the real reason for the error, but this is the only different thing I did in this switch,

I encountered an issue accessing the Cisco library. In the standard switch configuration, 
where the NPV mode is disabled, we typically import the library named "cisco" and utilize its functions, 
specifically "cli" and "clid," based on the required use case.

Steps to Reproduce:

  1. Enable NPV mode on the Cisco switch.
  2. Attempt to import the "cisco" library in python terminal.
  3. Attempt to use the functions "cli" and "clid."
     
     

    viniciusmarianoafonso_3-1727350728664.png

     

4 Replies 4

@vinicius-mariano-afonso odd one, not seen this - based only on the error  you have the python module six is not installed on this device, this module is commonly used for compatibility between python 2 and 3, providing a unified interface for various language features. What version of python are you running here looks like python 3? You might be able to fix this with pip install six. Also try this and share your output, be interesting to see this output.

# >>> import cisco
# >>> help(cisco)
Help on module cisco:

NAME
    cisco - commands that integrate with CLI

FILE
    (built-in)

FUNCTIONS
    cli(...)
        execute a cli command
    
    clid(...)
        execute a cli command, return name/value pairs
    
    clip(...)
        execute a cli command, dont return it, just display it
    
    set_vrf(...)
        specify the vrf name for socket operations

 It could be bug on the version, seen something like this, but not the same. So its always worth checking the version release notes too.

Hope this helps.

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

Hello!

I'm using Python 3.8.14, and I can't use pip

viniciusmarianoafonso_0-1727358821168.png

 

@vinicius-mariano-afonso what was the output from the help(cisco)? It looks like from your screen grab you are trying this from the exec prompt on the cli, in or to do this, you would need to run (or pip3)

nxos# guestshell run pip install six

or go into guestshell, the linux side of the switch

nxos# guestshell
[admin@guestshell ~]$ pip install six

 Hope this helps.

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

@vinicius-mariano-afonso i just has a second thought.... cli is not part of the Cisco package. So you do not need six package installed. Just import cli and this should work.

nxos# guestshell run python
Python 2.7.5 (default, Jun 28 2022, 15:30:04)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from cisco import cli
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name cli
>>> from cisco import clid
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name clid
>>> import cli
>>> 
>>> help(cli)
Help on module cli:

NAME
    cli

FILE
    /usr/lib64/python2.7/site-packages/cli.py

FUNCTIONS
    cli(cmd)

    clid(cmd)

    clip(cmd)


>>>

 

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