Crucial dependencies are missing - can't use redisai module
sandroci opened this issue ยท 7 comments
Hi everyone
It looks like numpy
and six
is missing as dependency in the setup.py. If I install pip install redisai
in a complete new virtualenv, it is not possible to use redisai in my python projects. Following error occurs:
Python 3.7.5 (default, Oct 17 2019, 12:21:00)
[GCC 8.3.1 20190223 (Red Hat 8.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import redisai
Traceback (most recent call last):
File "", line 1, in
File "/home/user/python_project/test_env/lib/python3.7/site-packages/redisai/init.py", line 2, in
from .client import Client
File "/home/user/python_project/test_env/lib/python3.7/site-packages/redisai/client.py", line 10, in
from .utils import str_or_strsequence, to_string
File "/home/user/python_project/test_env/lib/python3.7/site-packages/redisai/utils.py", line 1, in
import six
ModuleNotFoundError: No module named 'six'
>>>`
In the utils.py module you import on line 1 six
Installing pip install six
does not solve the issue:
Collecting six
Downloading
Installing collected packages: six
Successfully installed six-1.13.0
Python 3.7.5 (default, Oct 17 2019, 12:21:00)
[GCC 8.3.1 20190223 (Red Hat 8.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import redisai
Traceback (most recent call last):
File "", line 1, in
File "/home/user/python_project/test_env/lib/python3.7/site-packages/redisai/init.py", line 2, in
from .client import Client
File "/home/user/python_project/test_env/lib/python3.7/site-packages/redisai/client.py", line 11, in
from .tensor import Tensor, BlobTensor
File "/home/user/python_project/test_env/lib/python3.7/site-packages/redisai/tensor.py", line 62, in
class BlobTensor(Tensor):
File "/home/user/python_project/test_env/lib/python3.7/site-packages/redisai/tensor.py", line 102, in BlobTensor
def to_numpy(self) -> np.array:
AttributeError: 'NoneType' object has no attribute 'array'`
It is necessary to install numpy
as well that it works.
The root cause itself lies in the tensor.py module. On line 102 you have following method:
def to_numpy(self) -> np.array:
a = np.frombuffer(self.value[0], dtype=self._to_numpy_type(self.type))
return a.reshape(self.shape)
If numpy as not been installed, you set on line 8 in the tensor.py
module to None
:
try:
import numpy as np
except (ImportError, ModuleNotFoundError):
np = None
This can not work if you specify the return type for the previous to_numpy
method to np.array
.
I would recommend to fix this issue that you add six
and numpy
in the setup.py module following dependencies on line 24
install_requires=['redis', 'hiredis', 'rmtest', 'six', 'numpy']
Looking forward to help you to fix this issue ๐
Best regards,
Sandro
Hi @sandroci, Thanks a lot for raising the issue. The reason why we left those out is to keep the dependencies limited but since numpy being the first-class datatype in redisai python client now, it makes sense to add that into the dependencies. Can you open a PR, please (It might require some cleanups as well, like the exception check for numpy import error needs to be removed and probably there are others)?
Hi @hhsecond
Thank you for your fast reply ๐ I will create the PR during this week including the cleanup like removing the mentioned exception check and I will lookout for other obsolete checks.
Hi @sandroci,
I am pushing another version of redisai-py today or tomorrow. Did you get a chance to do this?
I'll be happy to merge if you made this already else, I'll add this also to my PR and merge. Let me know what works for you
Hi @hhsecond
I have made the small fix and opened the PR. I saw now that my Black formatter (https://github.com/psf/black) has reformatted the code. If this should be a problem and creates inconsistencies with your code style, I will remove the formatting ๐
Hi @hhsecond
Any news about my PR? Looking forward to complete all necessary steps to make it mergeable.
Best regards,
Sandro
@sandroci Sorry it took a bit. I just submitted my review with change requests. Once you could finish that, we are good to merge
Thanks,
S
Closing because of inactivity