SNMP support for Python under Windows

Peter Hansen peter at engcorp.com
Wed Jul 9 20:35:57 EDT 2003


WIWA wrote:
> 
> I did two things, both unsuccessfull:
> 
> 1) If I install the pySNMP modules under lib/site-packages and then
> type sth like:
> from pysnmp import session it gives the error message "ImportError: No
> module named pysnmp". The same happens if I unstall pySNMP directly
> under the lib directory. Installs in this context means 'copy paste'
> the *.py files of the pySNMP distribution.

I misled you the first time, but have since taken another look 
at the installation to see how it works.  In order to import
anything from a package (roughly, a set of .py files that includes an 
__init__.py file), you need to put those files in a directory
which is named for the package (e.g. pysnmp in this case) _and_ 
which is available in sys.path.  (Do "import sys" and "sys.path"
to see the list.  You probably have lib/site-packages in that
list, so just put all the PySNMP files under it in a folder called
pysnmp.)

> - Do I need to explicitly mention in my script where pySNMP is
> installed?

Not if it's in a folder called pysnmp that is itself in one of the
sys.path folders, or under the current folder.

> 2) I installed distutils 1.0.2 for Windows and it installed into the
> Python directory. So ar so good, I think...

Distutils is included in Python so you probably didn't need to do 
that, and maybe shouldn't have.  I'm not sure whether that will have 
broken the standard distutils.  It's repairable if it did.  On my
Python 2.2.1 setup here, the standard distutils is v1.0.3.

> I go to DOS prompt and go to the directory where disutils is installed
> and type in python setup.py install, but DOS replies:
> 'Python is not recognized as an internal or external command, program
> or batchfile".

Now that's a different problem.  You need python.exe to be findable
from the DOS PATH.  The simplest approach might be to check the FAQ
entry at http://www.python.org/cgi-bin/faqw.py?req=show&file=faq08.018.htp

As a test of the pysnmp installation, without having to change PATH
at all, change to the Python directory ("cd \python" or whatever)
and run the interactive interpreter ("python") and just type 
"import pysnmp" to see if it works.

> System coordinates are Windows XP. Python version is 2.2.2 and pySNMP
> is version 3.0.0.

Should all be no problem, although I suspect instructions in that
FAQ entry may be a little light on XP advice.  Let us know if you
see any area that could be improved so others can benefit from this
exchange...

-Peter




More information about the Python-list mailing list