I’m using Centos7 and I’m trying to run an python script using the pysnmp module, but I get this below, any ideas what I’m doing wrong here please?
Traceback (most recent call last):
File "snmpv2.py", line 2, in <module>
from pysnmp.entity.rfc3413.oneliner import cmdgen
ModuleNotFoundError: No module named 'pysnmp'
I try to install it
[root@svr-monitor pythlonstuff]# python -m pip install pysnmp
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Requirement already satisfied: pysnmp in /usr/lib/python2.7/site-packages (4.4.12)
Requirement already satisfied: pyasn1>=0.2.3 in /usr/lib/python2.7/site-packages (from pysnmp) (0.5.0)
Requirement already satisfied: pycryptodomex in /usr/lib64/python2.7/site-packages (from pysnmp) (3.19.0)
Requirement already satisfied: pysmi in /usr/lib/python2.7/site-packages (from pysnmp) (0.3.4)
Requirement already satisfied: ply in /usr/lib/python2.7/site-packages (from pysmi->pysnmp) (3.11)
You uses python3 to run the script.
But you used python2 to install pysnmp (I am assuming that python is python2 not python3 from the deprecation message).
Try using python3 to install pysnmp.
The packages for python2 and python3 are installed in seperate places.
As the warning said when you installed it, Python 2.7 is very out of date. If it came with your computer, do not try to remove it, as you can seriously damage your operating system. However, it is strongly recommended to write new code in a modern version of Python unless you know what you are doing and have a very compelling reason.
You can configure your system so that the
python command means Python 3, and then it will be harder to use Python 2.7 for your own code (or library installation) accidentally. The right way to do this depends on your distro; I found this quickly for CentOS.
Centos 7 is very old and it is likely dangerous to change python to mean python3 on such an old OS. Python2 was current when it first shipped and scripts will assume its python2.
I’ll take your word for it; I’m pretty sure I’ve only experienced Debian/Ubuntu (currently on Mint) and Fedora. For me it’s recommended to just use packages like
apt install pythonispython3 and it just fixes the symlinks, nice and user friendly and no negative consequences.