numpy.ufunc 大小错误,请尝试重新编译。即使是最新的 pandas 和 numpy 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53904157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 06:13:42  来源:igfitidea点击:

numpy.ufunc has the wrong size, try recompiling. even with the latest pandas and numpy versions

pythonpandasnumpy

提问by NotSoShabby

Im using pandas in a container and I get the following error:

我在容器中使用Pandas,但出现以下错误:

Traceback (most recent call last):
  File "/volumes/dependencies/site-packages/celery/app/trace.py", line 374, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/volumes/dependencies/site-packages/celery/app/trace.py", line 629, in __protected_call__
    return self.run(*args, **kwargs)
  File "/volumes/code/autoai/celery/data_template/api.py", line 16, in run_data_template_task
    data_template.run(data_bundle, columns=columns)
  File "/volumes/code/autoai/models/data_template.py", line 504, in run
    self.to_parquet(data_bundle, columns=columns)
  File "/volumes/code/autoai/models/data_template.py", line 162, in to_parquet
    }, parquet_path=data_file.path, directory="", dataset=self)
  File "/volumes/code/autoai/core/datasets/parquet_converter.py", line 46, in convert
    file_system.write_dataframe(parquet_path, chunk, directory, append=append)
  File "/volumes/code/autoai/core/file_systems.py", line 76, in write_dataframe
    append=append)
  File "/volumes/dependencies/site-packages/pandas/core/frame.py", line 1945, in to_parquet
    compression=compression, **kwargs)
  File "/volumes/dependencies/site-packages/pandas/io/parquet.py", line 256, in to_parquet
    impl = get_engine(engine)
  File "/volumes/dependencies/site-packages/pandas/io/parquet.py", line 40, in get_engine
    return FastParquetImpl()
  File "/volumes/dependencies/site-packages/pandas/io/parquet.py", line 180, in __init__
    import fastparquet
  File "/volumes/dependencies/site-packages/fastparquet/__init__.py", line 8, in <module>
    from .core import read_thrift
  File "/volumes/dependencies/site-packages/fastparquet/core.py", line 13, in <module>
    from . import encoding
  File "/volumes/dependencies/site-packages/fastparquet/encoding.py", line 11, in <module>
    from .speedups import unpack_byte_array
  File "__init__.pxd", line 861, in init fastparquet.speedups
ValueError: numpy.ufunc has the wrong size, try recompiling. Expected 192, got 216

I read on other answersthat this message shows up when pandas is compiled against a newer numpy version than the one you have installed. But updating both pandas and numpy did not work for me. I tried to find out if I have a few versions of numpy, but pip show numpyseems to show the latest version.

我在其他答案中读到,当 Pandas 是针对比您安装的版本更新的 numpy 版本编译时,会显示此消息。但是同时更新 pandas 和 numpy 对我不起作用。我试图找出我是否有几个版本的 numpy,但pip show numpy似乎显示了最新版本。

Also, in a weird way, this happens only when I deploy locally and not on the server.

此外,以一种奇怪的方式,只有当我在本地而不是在服务器上部署时才会发生这种情况。

Any ideas how to go about fixing that? Or at least how to debug my numpy and pandas versions (if there are multiple versions how do I check that)

任何想法如何解决这个问题?或者至少如何调试我的 numpy 和 pandas 版本(如果有多个版本,我该如何检查)

I tried: upgrading both packages and removing and reinstalling them. No help there.

我尝试过:升级两个软件包并删除并重新安装它们。没有帮助。

采纳答案by NotSoShabby

The answer was that fastparquet (a package that is used by pandas) was using numpy older binary file for some reason.

答案是 fastparquet(pandas 使用的一个包)出于某种原因使用了 numpy 较旧的二进制文件。

Updating that package helped. I guess that if someone else comes around this problem, to try and update all the related packages (that use numpy) will be the right way to go

更新那个包有帮助。我想如果其他人解决了这个问题,尝试更新所有相关的包(使用 numpy)将是正确的方法

回答by voglster

TLDR: If docker add:

TLDR:如果 docker 添加:

RUN pip install numpy

beforeyou install pandas (probably just your pip install -r requirements.txt) and it will just work again.

你安装 pandas(可能只是你的 pip install -r requirements.txt)之前,它会再次工作。

I am doing this in docker building pandas in alpine and run into the same issue and it JUST popped up (Dec 27th ish 2018) for a build that's been working just fine previously.

我正在 docker build pandas in alpine 中执行此操作并遇到相同的问题,并且它刚刚出现(2018 年 12 月 27 日左右)用于之前运行良好的构建。

回答by Jason D

well actually my problem was solved somehow by

好吧,实际上我的问题以某种方式解决了

 pip uninstall numpy
 pip install numpy

the real process is

真正的过程是

?  ~ pip3 uninstall numpy -y
Uninstalling numpy-1.14.5:
  Successfully uninstalled numpy-1.14.5
?  ~ pip3 install numpy     
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (1.16.1)
?  ~ pip3 uninstall numpy   
Uninstalling numpy-1.16.1:
  Would remove:
    /usr/bin/f2py3
    /usr/bin/f2py3.7
    /usr/lib/python3/dist-packages/numpy
    /usr/lib/python3/dist-packages/numpy-1.16.1.egg-info
Proceed (y/n)? y
  Successfully uninstalled numpy-1.16.1
?  ~ pip3 install numpy   
Collecting numpy...

which means the problem might be version conflict?

这意味着问题可能是版本冲突?

回答by yann

Make sure that the right version of numpy is installed on /volumes/dependencies/site-packages/and you are using it.

确保安装了正确版本的 numpy/volumes/dependencies/site-packages/并且您正在使用它。

回答by kbenda

I had the same issue as above. My solution was to install Python 2.7 from the official website: https://www.python.org/downloads/release/python-2713/

我遇到了与上述相同的问题。我的解决方案是从官网安装Python 2.7:https: //www.python.org/downloads/release/python-2713/

回答by gavinest

I had the same issue and tried all the above responses (at the time of writing). The only thing that worked for me was switching to pyarrow.

我遇到了同样的问题并尝试了上述所有回复(在撰写本文时)。唯一对我有用的是切换到pyarrow.

I then made sure to specify the pyarrowengine when using parquet in pandas. Although pandas should default to the pyarrowengine before fastparquetaccording to the docs.

然后我确保pyarrow在Pandas中使用镶木地板时指定引擎。尽管根据文档,pandas 之前应该默认使用pyarrow引擎fastparquet

pd.read_parquet('./path', engine='pyarrow')

回答by manfred

I had the same issue with pandas. This problem was solved by doing the following workaround,

我对Pandas有同样的问题。通过执行以下解决方法解决了此问题,

pip uninstall --yes numpy

easy_install --upgrade numpy