cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
952
Views
0
Helpful
1
Replies

NSO script command and PIP

romain.guilloux
Level 1
Level 1

Hello,

 

I've made a python package that I have install using pip, in NSO I have created a cli command that uses my python package but it failed : I want to know which python and pip NSO uses ? and how to create a script command using external python package in NSO ?

In bin/ncs-start-python I have set python3.4 to be used by NSO.

 

In a shell, when I perform pip3.4 freeze I have :

...
my-package==0.0.1
...

I have made a test to print it in NSO which showed this :

in test.sh  :

 

set -e
while [ $# -gt 0 ]; do
    case "$1" in
        --command)
            cat << EOF

begin command
    modes: oper
    styles: c i j
    cmdpath: echo-totot
    help: echo toto
end
EOF
            exit
            ;;
        *)
            break
            ;;
    esac
    shift
done

echo `which python3.4`
echo `which pip3.4`
echo `pip3.4 freeze`

 

 

I performed a package reload, a script reload and launched my command :

rguilloux@ncs# echo-totot
/usr/bin/python3.4
/usr/bin/pip3.4

So :

1- global python3.4 is used

2- global pip3.4 is used

3- It doesn't show any python package

 

How to use a pip package in NSO script command ?

Any help please ?

 

Romain

1 Accepted Solution

Accepted Solutions

mvolf
Cisco Employee
Cisco Employee

For running and testing ncs/python code/... in different Python environments I use virtualenv - I create a new or use existing virtual environment, switch to it and start NSO there, NSO and anything started from NSO happily picks whatever the environment provides. Looks to me this would work for you as well.

View solution in original post

1 Reply 1

mvolf
Cisco Employee
Cisco Employee

For running and testing ncs/python code/... in different Python environments I use virtualenv - I create a new or use existing virtual environment, switch to it and start NSO there, NSO and anything started from NSO happily picks whatever the environment provides. Looks to me this would work for you as well.