ImportError: cannot import name host

Asked by santosh on 2019-09-18

when i run mediaproxy , i am getting import error :-

root@santo-VirtualBox:/usr/lib/python2.7/dist-packages/application# /usr/bin/media-dispatcher --no-fork
Traceback (most recent call last):
  File "/usr/bin/media-dispatcher", line 47, in <module>
    from mediaproxy.dispatcher import Dispatcher
  File "/usr/lib/python2.7/dist-packages/mediaproxy/", line 27, in <module>
    from mediaproxy.configuration import DispatcherConfig
  File "/usr/lib/python2.7/dist-packages/mediaproxy/configuration/", line 4, in <module>
    from application.system import host
ImportError: cannot import name host

i tried to explore on application.system , it contains a class whose instance is host which is imported in File "/usr/lib/python2.7/dist-packages/mediaproxy/configuration/

why is it showing this error??
can someone help me ?? I am stuck here
thanks in advance

Question information

English Edit question
Ubuntu pam Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Manfred Hampl (m-hampl) said : #1

Is this an Ubuntu package, or from a foreign source? In the latter case please ask there.

santosh (santo407) said : #2

i am trying to install mediaproxy where this error has arisen's a import error which should haven't occurred because the required package,class and its object is there . so there should have been no issues but i am getting one.
i have explored here and there , but of no success.

here is /dist-packages/application/ :-

__all__ = 'host', 'makedirs', 'openfile', 'unlink', 'FileExistsError'

# System properties and attributes

class HostProperties(object):
    """Host specific properties"""

    __metaclass__ = Singleton

    def outgoing_ip_for(destination):
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            s.connect((destination, 1))
            return s.getsockname()[0]
        except socket.error:
            return None

    def default_ip(self):
        The default IP address of this system. This is the IP address of the
        network interface that has the default route assigned to it or in other
        words the IP address that will be used when making connections to the
        return self.outgoing_ip_for('')

    def name(self):
        return socket.gethostname()

    def fqdn(self):
        return socket.getfqdn()

    def domain(self):
        return socket.getfqdn()[len(socket.gethostname())+1:] or None

    def aliases(self):
        hostname = socket.gethostname()
        aliases = socket.gethostbyaddr(hostname)[1]
        if hostname in aliases:
        return aliases

host = HostProperties()

here is :- /dist-packages/mediaproxy/configuration/

from application.configuration import ConfigSection, ConfigSetting
from application.configuration.datatypes import IPAddress, NetworkRangeList
from application.system import host
from mediaproxy import configuration_filename
from mediaproxy.configuration.datatypes import AccountingModuleList, DispatcherIPAddress, DispatcherAddressList, DispatcherManagementAddress, PortRange, PositiveIntege$

class DispatcherConfig(ConfigSection):
    __cfgfile__ = configuration_filename
    __section__ = 'Dispatcher'

    socket_path = "dispatcher.sock"
    listen = ConfigSetting(type=DispatcherIPAddress, value=DispatcherIPAddress("any"))
    listen_management = ConfigSetting(type=DispatcherManagementAddress, value=DispatcherManagementAddress("any"))
    relay_timeout = 5 # How much to wait for an answer from a relay
    relay_recover_interval = 60 # How much to wait for an unresponsive relay to recover, before disconnecting it
    cleanup_dead_relays_after = 43200 # 12 hours
    cleanup_expired_sessions_after = 86400 # 24 hours
    management_use_tls = True
    accounting = ConfigSetting(type=AccountingModuleList, value=[])
    passport = ConfigSetting(type=X509NameValidator, value=None)
    management_passport = ConfigSetting(type=X509NameValidator, value=None)

class RelayConfig(ConfigSection):
    __cfgfile__ = configuration_filename
    __section__ = 'Relay'

    relay_ip = ConfigSetting(type=IPAddress, value=host.default_ip)
    advertised_ip = ConfigSetting(type=IPAddress, value=None)
    stream_timeout = 90
    on_hold_timeout = 7200

i am performing it on ubuntu 18.04 and python package is 2.7.
Please help

Manfred Hampl (m-hampl) said : #3

You are not using Ubuntu-provided programs, but software from somewhere else.
Even the file /dist-packages/application/ seems to be a foreign version.

The contents of /usr/lib/python2.7/dist-packages/application/ on my system (from the package python-application) begin with

# Copyright (C) 2006-2012 Dan Pascu. See LICENSE for details.

"""Interaction with the underlying operating system"""

__all__ = ['host', 'makedirs', 'unlink']

This is different from what you pasted above.
I do not know why you hav a different version of - most probably that one is also coming from a foreign source and is not the Ubuntu-provided version.

We cannot help if the programs on your system differ from the Ubuntu-provided version.

santosh (santo407) said : #4

got it solved ....the import was intended from another package containing python2.7 application.
two instances of python2.7 was present which was causing the conflict and hence the import error.

thanks for ur help...cheers!