08-21-2018 02:01 AM
I'd like to use the 'ipaddress' python library in an NSO package. Normally, I'd do 'pip2 install ipaddress' in a virtualenv to install the library and then import it using 'import ipaddress' in my python code.
How can external Python libraries be added and used with the Python-VM of NSO?
Solved! Go to Solution.
08-21-2018 02:20 AM
The simplest way is to make sure that PYTHONPATH is set correctly when starting NSO.
More advanced, there is a setting set python-vm start-command, by default it runs
$NCS_DIR/bin/ncs-start-python-vm.
There is some additional documentation in the developer's guide on how to go about changing which python is started.
08-21-2018 02:20 AM
The simplest way is to make sure that PYTHONPATH is set correctly when starting NSO.
More advanced, there is a setting set python-vm start-command, by default it runs
$NCS_DIR/bin/ncs-start-python-vm.
There is some additional documentation in the developer's guide on how to go about changing which python is started.
08-21-2018 02:51 AM
Thanks. I added the path to my library to PYTHONPATH in $NCS_DIR/bin/ncs-start-python-vm:
#!/bin/sh
pypath="${NCS_DIR}/src/ncs/pyapi"
ipaddrpath="/Users/tgdgyma/ipaddr/lib/python2.7/site-packages"
# Make sure everyone finds the NCS Python libraries at startup
if [ "x$PYTHONPATH" != "x" ]; then
PYTHONPATH=${ipaddrpath}:${pypath}:$PYTHONPATH
else
PYTHONPATH=${ipaddrpath}:${pypath}
fi
export PYTHONPATH
main="${pypath}/ncs_pyvm/startup.py"
echo "Starting ${main} $*"
exec python -u ${main} $*
08-21-2018 05:33 AM
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