Python:导入来自哪里?

时间:2019-05-13 13:26:29

标签: python-2.7 python-import pyro

在python 2.7中导入时遇到了这个奇怪的问题

我的应用程序位于一个目录中,该目录中包含一些子目录和更多的python应用程序,这些应用程序使用Pyro Name Server相互通信。

当我运行我的一个应用程序时,调用子方法之一会导致导入时崩溃。

这里是例外:

Traceback (most recent call last):
  File "ps_logic.py", line 15840, in <module>
    ps_logic = PSLogic(pyro_objects, cfg_handler, status_distributor, voip_processing)
  File "ps_logic.py", line 590, in __init__
    self.smarthopper_initial_check()
  File "ps_logic.py", line 12824, in smarthopper_initial_check
    counters_compared = self.smarthopper_maintenance_action()
  File "ps_logic.py", line 12928, in smarthopper_maintenance_action
    status = self.smart_hopper_logic.status_get()
  File "/home/app_core/flexcore/003-480/ps_logic/smart_devices_logic.py", line 203, in status_get
    return SmartStatusAugmented(self.smart_obj.queue_status_get(), self.smart_obj)
  File "/usr/lib/python2.7/site-packages/Pyro/core.py", line 381, in __call__
    return self.__send(self.__name, args, kwargs)
  File "/usr/lib/python2.7/site-packages/Pyro/core.py", line 456, in _invokePYRO
    return self.adapter.remoteInvocation(name, Pyro.constants.RIF_VarargsAndKeywords, vargs, kargs)
  File "/usr/lib/python2.7/site-packages/Pyro/protocol.py", line 497, in remoteInvocation
    return self._remoteInvocation(method, flags, *args)
  File "/usr/lib/python2.7/site-packages/Pyro/protocol.py", line 536, in _remoteInvocation
    answer = pickle.loads(answer)
ImportError: No module named drivers.smart.smart_common_const

它显然说它不能导入drivers.smart.smart_common_const,但是问题是,我的代码中没有该行。

如果我尝试查找该行在哪个文件中(因为我已经在某些文件中对其进行了修复),它什么也找不到:

app_core@003-481 ~/flexcore/003-480 $ grep -R "from drivers.smart.smart_common_const import" .
./drivers/.svn/pristine/23/23e13acbf9e604f179d4625e18b2b992116a98a1.svn-base:from drivers.smart.smart_common_const import *
./drivers/.svn/pristine/65/65655973d3c70a16cc982db59db8f2989366524b.svn-base:from drivers.smart.smart_common_const import *
./drivers/.svn/pristine/3b/3ba2e2518e64db9188b63247b763926544bddd90.svn-base:from drivers.smart.smart_common_const import *
app_core@003-481 ~/flexcore/003-480 $

但是svn文件。

我一直在运行带有-v选项的python应用程序,以查找其试图从该文件导入的位置。但是它不会在该异常之前返回调试行,所以我猜它以前已经导入过,或者如果导入失败则什么也不显示。

我还删除了所有*.pyc文件并重新启动了计算机,以确保内存中没有剩余,但问题仍然存在。

还有其他选择如何找出问题出在哪里?我开始感到绝望了。

1 个答案:

答案 0 :(得分:0)

该PS_Logic(无论它可能是什么)似乎都在使用Pyro对服务器进行远程调用。特别是以下内容似乎是远程调用:

self.smart_obj.queue_status_get()

服务器发回一个自定义对象,并且由于它使用pickle作为序列化格式,因此您的客户端程序尝试重建该对象。显然,您的客户端代码中没有可用的正确模块,因为 pickle 会在尝试为您导入所需模块(将响应重新组装为对象)时失败。

该ps_logic模块的手册中必须包含一些内容,可告诉您如何正确使用它,以及您也应该在客户端中安装它。

(建议不要顺便使用咸菜,并坚持使用Pyro的默认序列化程序,但这是另一回事了)