thunlp / OpenNE

An Open-Source Package for Network Embedding (NE)
MIT License
1.68k stars 485 forks source link

ValueError: numpy.ufunc has the wrong size, try recompiling. Expected 192, got 216 #71

Closed codeinging closed 4 years ago

codeinging commented 5 years ago

当我安装完环境运行python -m openne --help时出现以下错误: File "/root/anaconda2/envs/nepython3.4/lib/python3.4/runpy.py", line 170, in _run_module_as_main "main", mod_spec) File "/root/anaconda2/envs/nepython3.4/lib/python3.4/runpy.py", line 85, in _run_code exec(code, run_globals) File "/root/sunyundong/network_embedding/code/OpenNE/src/openne/main.py", line 7, in from . import node2vec File "/root/sunyundong/network_embedding/code/OpenNE/src/openne/node2vec.py", line 3, in from gensim.models import Word2Vec File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/gensim/init.py", line 6, in from gensim import parsing, matutils, interfaces, corpora, models, similarities, summarization, utils # noqa:F401 File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/gensim/models/init.py", line 7, in from .coherencemodel import CoherenceModel # noqa:F401 File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/gensim/models/coherencemodel.py", line 29, in from gensim.topic_coherence import (segmentation, probability_estimation, File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/gensim/topic_coherence/probability_estimation.py", line 14, in from gensim.topic_coherence.text_analysis import ( File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/gensim/topic_coherence/text_analysis.py", line 23, in from gensim.models.word2vec import Word2Vec File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/gensim/models/word2vec.py", line 131, in from gensim.models.word2vec_inner import train_batch_sg, train_batch_cbow File "init.pxd", line 861, in init gensim.models.word2vec_inner (./gensim/models/word2vec_inner.c:11403) ValueError: numpy.ufunc has the wrong size, try recompiling. Expected 192, got 216 (nepython3.4) [root@localhost src]# cd .. (nepython3.4) [root@localhost OpenNE]# python -m openne --help /root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/smart_open/ssh.py:34: UserWarning: paramiko missing, opening SSH/SCP/SFTP paths will be disabled. pip install paramiko to suppress warnings.warn('paramiko missing, opening SSH/SCP/SFTP paths will be disabled. pip install paramiko to suppress') Traceback (most recent call last): File "/root/anaconda2/envs/nepython3.4/lib/python3.4/runpy.py", line 170, in _run_module_as_main "main", mod_spec) File "/root/anaconda2/envs/nepython3.4/lib/python3.4/runpy.py", line 85, in _run_code exec(code, run_globals) File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/openne-0.0.0-py3.4.egg/openne/main.py", line 7, in from . import node2vec File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/openne-0.0.0-py3.4.egg/openne/node2vec.py", line 3, in from gensim.models import Word2Vec File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/gensim/init.py", line 6, in from gensim import parsing, matutils, interfaces, corpora, models, similarities, summarization, utils # noqa:F401 File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/gensim/models/init.py", line 7, in from .coherencemodel import CoherenceModel # noqa:F401 File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/gensim/models/coherencemodel.py", line 29, in from gensim.topic_coherence import (segmentation, probability_estimation, File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/gensim/topic_coherence/probability_estimation.py", line 14, in from gensim.topic_coherence.text_analysis import ( File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/gensim/topic_coherence/text_analysis.py", line 23, in from gensim.models.word2vec import Word2Vec File "/root/anaconda2/envs/nepython3.4/lib/python3.4/site-packages/gensim/models/word2vec.py", line 131, in from gensim.models.word2vec_inner import train_batch_sg, train_batch_cbow File "init.pxd", line 861, in init gensim.models.word2vec_inner (./gensim/models/word2vec_inner.c:11403) ValueError: numpy.ufunc has the wrong size, try recompiling. Expected 192, got 216

justdoit0823 commented 5 years ago

I also met the above problem when building the openne framework within a Python3 docker environment. Then I found an issue 12785 in numpy github issue list. The main reason is that gensim package is built with different numpy C-API version rather than the current version within your python environment.

However, I find a simple solution, don't use the binary gensim version from pypi.

pip install -r requirements.txt --no-binary gensim

@codeinging you could try to fix it in this way, good luck to you, 😄。

minstar commented 5 years ago

Hello, I still have this error even if I installed requirements.txt with @justdoit0823 option. ValueError: numpy.ufunc has the wrong size, type recompiling. Expected 192, got 216 Is there any other solution?

justdoit0823 commented 5 years ago

@codeinging @minstar I have got the root cause of this question. The numpy is necessary when building gensim package, and the required version is declared as numpy >= 1.11.3. However the latest numpy version is 1.17.0, and the building dependencies of numpy version great than or equal to 1.16.0 have changed also. The following is quoted from numpy 1.16.0 release notes,

Downstream developers building this release should use Cython >= 0.29 and, if using OpenBLAS, OpenBLAS > v0.3.4.

Miserably word2vec_inner.c file of version 3.0.1 is generated by Cython 0.25.2, but built with the latest numpy. So the runtime exception is raised when importing the module.

As the above, we could fix this problem in different ways, a) manually install the numpy 1.14.0 before the requirements.txt file, I have validated this with command docker run -it --rm justdoit/openne:1.0 -m openne --method node2vec within a docker environment ; b) upgrade the numpy version to 1.16.0 at least, and there may be potential incompatible code, which totally depends on the usage of numpy.

holacola1985 commented 5 years ago

downgrade to numpy==1.16 worked for my case @justdoit0823