Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crucial dependencies are missing - can't use redisai module #23

Closed
sandroci opened this issue Nov 10, 2019 · 7 comments
Closed

Crucial dependencies are missing - can't use redisai module #23

sandroci opened this issue Nov 10, 2019 · 7 comments

Comments

@sandroci
Copy link

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

@hhsecond
Copy link
Contributor

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)?

@sandroci
Copy link
Author

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.

@hhsecond
Copy link
Contributor

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

@sandroci
Copy link
Author

sandroci commented Nov 27, 2019

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 😃

@sandroci
Copy link
Author

Hi @hhsecond
Any news about my PR? Looking forward to complete all necessary steps to make it mergeable.
Best regards,
Sandro

@hhsecond
Copy link
Contributor

hhsecond commented Nov 29, 2019

@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

@hhsecond
Copy link
Contributor

Closing because of inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants