Python PIP

This topic is to discuss the following lesson:

Hi Rene
I am having issues importing parse from networkparse. Currently getting the following error:

"Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python39\lib\site-packages\networkparse\__init__.py", line 7, in 
    from . import parse
  File "C:\Python39\lib\site-packages\networkparse\parse.py", line 23, in 
    import pyparsing
ModuleNotFoundError: No module named 'pyparsing'"

I have added the path to python manually into Windows 10 but sadly that has not helped.

As an aside can I also ask you just to walk through the meaning and syntax of the
config = parse.ConfigIOS(running_configuration) section.

Many Thanks,
Frank

Hello Frank,

When you get an error like this:

ModuleNotFoundError: No module named 'pyparsing'"

It’s always related that Python is unable to find your module. In this case, it seems that the networkparse module is trying to import the pyparsing module. We can see it here:

File "C:\Python39\lib\site-packages\networkparse\parse.py", line 23, in 
    import pyparsing
ModuleNotFoundError: No module named 'pyparsing'"

When you look at the parse.py file, you can see this on line 23:

import pyparsing

Try using pip to install pyparsing:

pip install pyparsing

That should solve your issue.

Let me explain this line:

config = parse.ConfigIOS(running_configuration)

In our code, we used from networkparse import parse to import the parse module from the “networkparse” module.

If you want to see what parse.py looks like, we can check the git repository here:

I added this file to this post in case it changes in the future and someone wants to follow along.

networkparse_parse.txt (22.3 KB)

The parse module contains a class named ConfigIOS that we call. Our variable running_configuration is the argument that we send to the ConfigIOS class.

I haven’t explained classes in the course, it’s difficult to explain in one or two sentences. Python is an object-oriented programming language. In a nutshell, a class is a blueprint/template for an object. If you look at the code in the repository, you can see the ConfigIOS class is used to parse the configuration file for Cisco IOS.

Does this help? :slight_smile:

Rene

Hi Rene,

That is much better, and I now get no errors, and all commands appear to run.

I just don’t get any print from the code in the last phase, using your configuration file and/or similar .conf .txt etc.

Thanks,
Frank

It doesn’t work for me either. Any response would be appreciated.

from networkparse import parse
import ciscoconfparse
from networkparse import parse
config = parse.ConfigIOS(running_configuration)
Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘running_configuration’ is not defined
dir(ciscoconfparse)
[‘ACTIVE_LOGURU_HANDLERS’, ‘ALL_ASA_FACTORY_CLASSES’, ‘ALL_BRACE_SYNTAX’, ‘ALL_IOSXR_FACTORY_CLASSES’, ‘ALL_IOS_FACTORY_CLASSES’, ‘ALL_JUNOS_FACTORY_CLASSES’, ‘ALL_NXOS_FACTORY_CLASSES’, ‘ALL_VALID_SYNTAX’, ‘ASAAclLine’, ‘ASACfgLine’, ‘ASAHostnameLine’, ‘ASAIntfGlobal’, ‘ASAIntfLine’, ‘ASAName’, ‘ASAObjGroupNetwork’, ‘ASAObjGroupService’, ‘ASAObjNetwork’, ‘ASAObjService’, ‘BaseCfgLine’, ‘CFGLINE’, ‘CiscoConfParse’, ‘CiscoIOSInterface’, ‘CiscoIOSXRInterface’, ‘CiscoPassword’, ‘CiscoRange’, ‘ConfigList’, ‘DNSException’, ‘DNSResponse’, ‘Diff’, ‘DiffObject’, ‘ENCODING’, ‘HDiff’, ‘IOSAaaCommandsAccountingLine’, ‘IOSAaaCommandsAuthorizationLine’, ‘IOSAaaConsoleAuthorizationLine’, ‘IOSAaaEnableAuthenticationLine’, ‘IOSAaaExecAccountingLine’, ‘IOSAaaGroupServerLine’, ‘IOSAaaLoginAuthenticationLine’, ‘IOSAccessLine’, ‘IOSCfgLine’, ‘IOSHostnameLine’, ‘IOSIntfGlobal’, ‘IOSIntfLine’, ‘IOSRouteLine’, ‘IOSXRCfgLine’, ‘IOSXRIntfLine’, ‘IPv4Obj’, ‘IPv6Obj’, ‘InvalidParameters’, ‘JunosCfgLine’, ‘L4Object’, ‘MutableSequence’, ‘NXOSAaaCommandsAccountingLine’, ‘NXOSAaaCommandsAuthorizationLine’, ‘NXOSAaaConsoleAuthorizationLine’, ‘NXOSAaaEnableAuthenticationLine’, ‘NXOSAaaExecAccountingLine’, ‘NXOSAaaGroupServerLine’, ‘NXOSAaaLoginAuthenticationLine’, ‘NXOSAccessLine’, ‘NXOSCfgLine’, ‘NXOSHostnameLine’, ‘NXOSIntfGlobal’, ‘NXOSIntfLine’, ‘NXOSRouteLine’, ‘NXOSvPCLine’, ‘PythonOptimizeCheck’, ‘RequirementFailure’, ‘Resolver’, ‘Sequence’, ‘_’, ‘builtins’, ‘cached’, ‘ccp_re’, ‘doc’, ‘file’, ‘loader’, ‘name’, ‘package’, ‘path’, ‘spec’, ‘_get_ipv4’, ‘_get_ipv6’, ‘as_text_list’, ‘assign_parent_to_closing_braces’, ‘build_space_tolerant_regex’, ‘ccp_abc’, ‘ccp_logger_control’, ‘ccp_util’, ‘cfgobj_from_text’, ‘check_valid_ipaddress’, ‘ciscoconfparse’, ‘collapse_addresses’, ‘config_line_factory’, ‘configure_loguru’, ‘convert_junos_to_ios’, ‘copy’, ‘datetime’, ‘deprecated’, ‘dns6_lookup’, ‘dns_lookup’, ‘dns_query’, ‘enforce_valid_types’, ‘errors’, ‘fix_repeated_words’, ‘get_version_number’, ‘hier_config’, ‘initialize_ciscoconfparse’, ‘initialize_globals’, ‘inspect’, ‘ip_factory’, ‘is_not’, ‘junos_unsupported’, ‘locale’, ‘log_function_call’, ‘logger’, ‘models_asa’, ‘models_cisco’, ‘models_iosxr’, ‘models_junos’, ‘models_nxos’, ‘os’, ‘parse_global_options’, ‘parse_line_braces’, ‘partial’, ‘pathlib’, ‘protocol_values’, ‘re’, ‘reverse_dns_lookup’, ‘run_this_posix_command’, ‘sys’, ‘time’, ‘toml’, ‘warnings’, ‘yaml’]
dir(parse)
[‘ConfigASA’, ‘ConfigBase’, ‘ConfigFortigate’, ‘ConfigHPCommware’, ‘ConfigIOS’, ‘ConfigJunos’, ‘ConfigLine’, ‘ConfigLineList’, ‘ConfigNXOS’, ‘List’, ‘MultipleLinesError’, ‘NoLinesError’, ‘OneIndexedList’, ‘Optional’, ‘UnknownConfigError’, ‘VersionNumber’, ‘builtins’, ‘cached’, ‘doc’, ‘file’, ‘loader’, ‘name’, ‘package’, ‘spec’, ‘automatic’, ‘dataclass’, ‘line_parse_checker’, ‘math’, ‘namedtuple’, ‘pyparsing’, ‘re’]

Hello Sushil

Your particular case seems to be different than that described by @faithfps in his post here. In the output you shared, there is a NameError that states that the running_config variable is not defined. Make sure that, as in the lesson, you have parsed the configuration and assigned it to this config variable. Take a look at this particular configuration and let us know if you were able to resolve it.

I hope this has been helpful!

Laz