Project

General

Profile

Bug #2173

ping import failing

Added by Luke Murphey about 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Start date:
12/16/2017
Due date:
% Done:

100%


Description

Traceback (most recent call last):
  File "ping.py", line 17, in <module>
    from network_tools_app.ping_network import ping_all
  File "/opt/splunk/etc/apps/network_tools/bin/network_tools_app/ping_network.py", line 9, in <module>
    from modular_input.contrib import ipaddress
ImportError: No module named contrib

Associated revisions

Revision 240 (diff)
Added by lukemurphey about 4 years ago

Fixing failed import

Reference #2173

History

#1 Updated by Luke Murphey about 4 years ago

Odd, this works:

import os
import sys
sys.path.insert(0, 'modular_input.zip')
from modular_input.contrib import ipaddress

#2 Updated by Luke Murphey about 4 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100
Observations:
  1. This works on Mac for some reason; but not on Windows and Linux
  2. You can import things like "Field" but not from the contrib directory #
Questions:
  1. Does making the path absolute make it work?
    1. No
  2. Is the modular input library valid\
  3. Can fields be imported
    1. No: this fails: from modular_input.fields import Field
  4. Does zipimport work? https://pymotw.com/2/zipimport/
    1. Yes

path_to_mod_input_lib = os.path.join(os.path.dirname(os.path.abspath(file)), '../modular_input.zip')
import zipimport

importer = zipimport.zipimporter(path_to_mod_input_lib)
modular_input = importer.load_module('modular_input')

Also available in: Atom PDF