Reputation: 103
While testing my application using nosetests. I am getting some error related to import error:
The command I am using on Linux CLI is: 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
I had a searched for it and found that my redis.py is I guess being accessed before the redis module.
For more reference: https://gist.github.com/camfindlay/a8c080435960fe87388474839418f0f0#file-gistfile1-txt-L154
So, for this I had set my PYTHONPATH and PATH.
The Output of echo $PATH is as follows:
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
But I am still not able to resolve the issue.
Update 1: Attaching the error logs appearing on screen:
Upvotes: 1
Views: 2136
Reputation: 353
It looks like the file at /ckan/lib/redis.py
is conflicting with your redis package.
Can you use a virtual environment and install all dependencies?
After you are done with it, you can use following code -
from .redis import * #For importing something from your redis.py
from redis import ConnectionPool #For importing from redis module
Hope this helps. Cheers.
Upvotes: 1