pysnmp icon indicating copy to clipboard operation
pysnmp copied to clipboard

ModuleNotFoundError: No module named 'pysnmp'

Open atech1973 opened this issue 2 years ago • 4 comments

Hello I am new to this library and not that much familiar with Python.

I have installed python 3.9.4 in Win10x64 platform and pip 23.0.1 and installed pysnmp successfully using pip install pysnmp command. However, when I run an example code to "fetch snmp variable" from this library "Quick Start" page, (https://pysnmp.readthedocs.io/en/latest/quick-start.html). I get this error.

######################################################### SyntaxError: multiple statements found while compiling a single statement

=========================== RESTART: E:\Python\pysnmp\fetch snmp variable.py =========================== Traceback (most recent call last): File "E:\Python\pysnmp\fetch snmp variable.py ", line 1, in from pysnmp.hlapi import * ModuleNotFoundError: No module named 'pysnmp'

######################################################## pysnmp install dump. Collecting pysnmp Downloading pysnmp-4.4.12-py2.py3-none-any.whl (296 kB) ---------------------------------------- 296.5/296.5 kB 6.1 MB/s eta 0:00:00 Collecting pysmi Downloading pysmi-0.3.4-py2.py3-none-any.whl (80 kB) ---------------------------------------- 80.0/80.0 kB ? eta 0:00:00 Collecting pyasn1>=0.2.3 Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB) ---------------------------------------- 77.1/77.1 kB 4.2 MB/s eta 0:00:00 Collecting pycryptodomex Downloading pycryptodomex-3.17-cp35-abi3-win_amd64.whl (1.7 MB) ---------------------------------------- 1.7/1.7 MB 8.5 MB/s eta 0:00:00 Collecting ply Downloading ply-3.11-py2.py3-none-any.whl (49 kB) ---------------------------------------- 49.6/49.6 kB 2.6 MB/s eta 0:00:00 Installing collected packages: pyasn1, ply, pysmi, pycryptodomex, pysnmp Successfully installed ply-3.11 pyasn1-0.4.8 pycryptodomex-3.17 pysmi-0.3.4 pysnmp-4.4.12

atech1973 avatar Apr 03 '23 10:04 atech1973

To add more insight to this issue, I have discovered another similar thread to mine which alerted me to check the python pip list. Similar other thread link: https://github.com/etingof/pysnmp/issues/420

####################################### When I ran pip list I can see pysnmp was installed Package Version


pip 23.0.1 ply 3.11 pyasn1 0.4.8 pycryptodomex 3.17 pysmi 0.3.4 pysnmp 4.4.12

And py -m pip list command did not list pysnmp in the list but it gave me warning that I had an older pip installed.

Package Version


astroid 2.5.6 beautifulsoup4 4.9.3 certifi 2020.12.5 chardet 4.0.0 colorama 0.4.4 idna 2.10 isort 5.8.0 lazy-object-proxy 1.6.0 mccabe 0.6.1 pip 20.2.3 pylint 2.8.2 pytube 11.0.0 requests 2.25.1 setuptools 49.2.1 soupsieve 2.2.1 toml 0.10.2 urllib3 1.26.4 wrapt 1.12.1 WARNING: You are using pip version 20.2.3; however, version 23.0.1 is available. You should consider upgrading via the 'C:\Users\atech1973\AppData\Local\Programs\Python\Python39\python.exe -m pip install --upgrade pip' command.

I ran this command and old pip was updated.

c:\users\atech1973\batchfiles>C:\Users\atech1973\AppData\Local\Programs\Python\Python39\python.exe -m pip install --upgrade pip Collecting pip Using cached pip-23.0.1-py3-none-any.whl (2.1 MB) Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 20.2.3 Uninstalling pip-20.2.3: Successfully uninstalled pip-20.2.3 WARNING: The scripts pip.exe, pip3.9.exe and pip3.exe are installed in 'C:\Users\atech1973\AppData\Local\Programs\Python\Python39\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed pip-23.0.1

After this if run command py -m pip list > I still don't see pysnmp in the list but pip list shows me pysnmp in its list Package Version


pip 23.0.1 ply 3.11 pyasn1 0.4.8 pycryptodomex 3.17 pysmi 0.3.4 pysnmp 4.4.12

I anyone has had this experience then please if you can help me out?

atech1973 avatar Apr 03 '23 10:04 atech1973

Further to this problem resolution I have added my pip path to my environment path as well but still running the py -m pip list does not print the pysnmp being in the list.

If I type pip without anything else, the path is shorter then if I run pip -V command. see below. C:\Users\atech1973\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe -m pip [options]

As mentioned above, if I run pip -V command, I have pip Ver. 23.0.1 running but just noticed it's working directory is in a weird location and I am not sure if this is its working director that I should add to window path or the one above.

C:\Users\atech1973\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pip (python 3.9)

If I brows to the second long path location, I can see pysnmp diectory is in here.


Cryptodome pip pip-23.0.1.dist-info ply ply-3.11.dist-info pyasn1 pyasn1.0.4.8.dist-info pycryptodome-3.17.dist-info pysmi pysmi.0.3.4.dist-info pysnmp pysnmp-4.4.12.dist-info


atech1973 avatar Apr 03 '23 11:04 atech1973

Lastly I have added the following path to my Windows path Env. and still I get the same error when I run the program that tries to import pysnmp.

C:\Users\atech1973\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pysnmp

pysnmp error on run

atech1973 avatar Apr 03 '23 11:04 atech1973

  1. You are reading one of the worst sources of PySNMP documentation. Please read #429 for more details. That web page was set up by someone who has no relationship to the original author and has no intention to keep the information up-to-date or even technically correct. Unfortunately Google puts it at top of search results which shows how poor that search engine is.
  2. You will have to be a good enough Python user/developer in order to make good use of this library.

It will be rather lengthy to teach you enough Python, unless you buy great books/tutorials or just hire a consultant. So, the only tip I want to say is to learn the actual path of python.exe on your machine, and then perform all other operations with that executable. For example, use python.exe -m pip list and python.exe -m pip install to verify/install packages, then use python.exe yourscript.py to execute your test script.

A tool like VS Code + Microsoft Python extension can easily guide you on which python.exe to use, so I never use IDLE Shell or the editor you used.

lextm avatar Apr 13 '23 04:04 lextm