ImportError:无法导入名称ConnectionPool

时间:2019-05-28 09:14:33

标签: python python-2.7 ckan

使用鼻子测试测试我的应用程序时。我收到一些与导入错误有关的错误:

我在Linux CLI上使用的命令是:nosetests -m test_file

======================================================================
ERROR: Failure: ImportError (cannot import name ConnectionPool)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/lib/ckan/default/src/ckan/ckan/tests/views/test_admin.py", line 10, in <module>
    import ckan.tests.helpers as helpers
  File "/usr/lib/ckan/default/src/ckan/ckan/tests/helpers.py", line 32, in <module>
    import rq
  File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/rq/__init__.py", line 6, in <module>
    from .connections import (Connection, get_current_connection, pop_connection,
  File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/rq/connections.py", line 7, in <module>
    from redis import StrictRedis
  File "/usr/lib/ckan/default/src/ckan/ckan/lib/redis.py", line 15, in <module>
    from redis import ConnectionPool, Redis
ImportError: cannot import name ConnectionPool
-------------------- >> begin captured logging << --------------------
pyutilib.component.core.pca: DEBUG: Creating PluginEnvironment 'pca'
pyutilib.component.core.<default>: DEBUG: Creating PluginEnvironment '<default>'
pyutilib.component.core.<default>: DEBUG: Pushing environment '<default>' on the PluginGlobals stack
pyutilib.component.core.pca: DEBUG: Pushing environment 'pca' on the PluginGlobals stack
pyutilib.component.core.pca: DEBUG: Pushing environment 'pca' on the PluginGlobals stack
pyutilib.component.core.pca: INFO: Adding service IgnorePluginPlugins to environment pca
pyutilib.component.core.pca: INFO: Adding service IgnorePluginPlugins to environment pca
pyutilib.component.core.pca: DEBUG: Popping environment 'pca' from the PluginGlobals stack
passlib.utils.compat: DEBUG: loaded lazy attr 'BytesIO': <built-in function StringIO>
passlib.registry: DEBUG: registered 'pbkdf2_sha512' handler: <class 'passlib.handlers.pbkdf2.pbkdf2_sha512'>
--------------------- >> end captured logging << ---------------------

----------------------------------------------------------------------
Ran 1 test in 0.001s

我进行了搜索,发现我的redis.py可能是在redis模块之前被访问的。

有关更多参考:https://gist.github.com/camfindlay/a8c080435960fe87388474839418f0f0#file-gistfile1-txt-L154

因此,为此,我设置了 PYTHONPATH PATH

echo $ PATH的输出如下:

echo $PATH
/usr/lib/ckan/default/bin:/home/ubuntu64/bin:/home/ubuntu64/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/bin/python

但是我仍然无法解决问题。

更新1: 附加显示在屏幕上的错误日志:

enter image description here

1 个答案:

答案 0 :(得分:0)

/ckan/lib/redis.py上的文件似乎与您的redis软件包冲突。

您可以使用虚拟环境并安装所有依赖项吗?

完成后,可以使用以下代码-

from .redis import *  #For importing something from your redis.py
from redis import ConnectionPool  #For importing from redis module

希望这会有所帮助。 干杯。