FilippoBovo / robustats

Robustats is a Python library for high-performance computation of robust statistical estimators.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NumPy problems?

annemoree opened this issue · comments

Hello,
I am trying to use your robustas package. For this, I have conda installed numpy version 1.19.4 as listed in your requirements.txt, and pip installed robustats. I am using jupyterlab. I get the following error:


RuntimeError Traceback (most recent call last)
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

ImportError Traceback (most recent call last)
in
----> 1 import robustats

/oceandata01/moree/anaconda3/envs/env3/lib/python3.9/site-packages/robustats/init.py in
----> 1 from robustats.robustats import *

/oceandata01/moree/anaconda3/envs/env3/lib/python3.9/site-packages/robustats/robustats.py in
4 import numpy as np
5
----> 6 import _robustats
7
8

ImportError: numpy.core.multiarray failed to import

There seems to exist a problem with the version of numpy, do you know how I could resolve this? I am quite new to many aspects of this, so it is possible I am making a mistake of course.

Hey, @annemoree.

To help you, I need some information:

  • Are you using a Conda or Pip virtual environments or not virtual environment at all?
  • If you use Conda, did you install Numpy with the conda or pip commands?
  • What version of Numpy are you using?
  • What version of Robustats are you using?

Also, you may try to upgrade Numpy (pip install numpy --upgrade) or downgrade it, if upgrading does not work. Let me know.

Hi Filippo,
Thanks for your quick response!
I am not using a virtual environment.
I installed NumPy using conda, and then robustas using pip.
NumPy is version 1.19.4 as listed in your requirements.txt.
Robustats is at 0.1.7

If I upgrade NumPy to numpy-1.20.2 using pip in my conda environment, the error is resolved! However, conda does not recommend using pip for Conda-available packages like NumPy.

And I still don't understand why if following your requirements.txt file with NumPy 1.19.4, I get this error.
Anyway, I will leave it be now that it works, thank you for your help.

You're welcome.

Generally, it is always better to have a virtual environment for every project. You may create a virtual environment with Conda or Pip. Once you decide to use either Conda or Pip, stick to the one you choose. Mixing them may lead to results like the one that you had above.

I personally prefer Pip over Conda. For a primer on virtual environments, have a look at this link: https://realpython.com/python-virtual-environments-a-primer/

I hope this helps.

Hi, I am running into a similar issue, because I am also using TensorFlow and it depends on NumPy to <=1.19.5.
I can only do an import if robustats 0.1.7 is compiled with NumPy to >=1.20.
I tried minimal examples

working example:

in fresh venv with python3.8

pip install -r requirements.txt

with requirements.txt:

robustats==0.1.7
numpy>=1.20

it compiles, installs and I am able to do from robustats import weighted_median without any problems

failed example:

in a fresh venv with python3.8

pip install -r requirements.txt

with requirements.txt:

robustats==0.1.7
numpy<=1.19.5

it compiles but failed on import with the following message

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/snap/pycharm-professional/254/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "...venv_19/lib/python3.8/site-packages/robustats/__init__.py", line 1, in <module>
    from robustats.robustats import *
  File "/snap/pycharm-professional/254/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "...venv_19/lib/python3.8/site-packages/robustats/robustats.py", line 6, in <module>
    import _robustats
  File "/snap/pycharm-professional/254/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ImportError: numpy.core.multiarray failed to import

It seems like robustats 0.1.7 is incompatible with NumPy < 1.20.

I would suggest having this set in the setup.py. Having NumPy 0.19.4 in the requirements.txt of the robustats repository is confusing, as @annemoree pointed out before.

Hi, @emacholdt. Thanks for raising this issue.

I have just checked and Robustats 0.1.7 works both with Numpy 1.19.4 and 1.19.5.

Could you please test if the library works with a fresh installation of Numpy 1.19.4?

Also, what specific version of Python 3.8 are you using, and what is your OS?

Thanks.

Hi, thanks for coming back to the issue.
I am currently trying to use Python 3.8.10 on Kubuntu 20.04 (kernel 5.4.0-81-generic)

According to your suggestion, I tried both Numpy 1.19.4 and 1.19.5, each within fresh venvs, without success.

here is my install package list.

Package    Version
---------- -------
numpy      1.19.4
pip        21.2.4
robustats  0.1.7
setuptools 57.4.0
wheel      0.37.0

I installed NumPy and Robustats using pip.
numpy-1.19.5-cp38-cp38-manylinux2010_x86_64.whl or numpy-1.19.4-cp38-cp38-manylinux2010_x86_64.whl
robustats-0.1.7-cp38-cp38-linux_x86_64.whl

❯ python3.8
Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from robustats import weighted_median
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rico/Nextcloud/projects/fixrob/venvpeter/lib/python3.8/site-packages/robustats/__init__.py", line 1, in <module>
    from robustats.robustats import *
  File "/home/.../venv/lib/python3.8/site-packages/robustats/robustats.py", line 6, in <module>
    import _robustats
ImportError: numpy.core.multiarray failed to import

I don't know what I am doing wrong. Any ideas?

Hi, any solution for this issue?

No, unfortunately not. I ended up not using robustats anymore.

Hey, both. Thanks for your patience. The following line in the error message tells that the Numpy library used to compile Robustats and the Numpy library in your environment are different.

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

This is another GitHub issue stating the same problem: freqtrade/freqtrade#4281. The solution seems to be upgrading Numpy:

pip install numpy --upgrade