当前位置: 动力学知识库 > 问答 > 编程问答 >

python - How can I stop numpy_1.8 from masking numpy_1.10?

问题描述:

I had thought I was using the most recent version of numpy (1.10) At least, when I run pip list I see numpy (1.10.4). However, when I get into the python interpreter and type

import numpy

numpy.__version__

I see

'1.8.2'

I expect that the 1.8.2 got installed sometime after the 1.10 version, because I've recently installed some new packages and I now when I run some code that used to work, I get this error:

RuntimeError: module compiled against API version a but this version of numpy is 9

In OpenCV 2.4.8: module compiled against API version 9 the accepted answer mentioned that the numpy team refers to version 1.8 as numpy version 9. So, I think that I was originally using numpy_1.10, and somehow got numpy_1.8 installed.

My first question is How did this happen and how can I guard against it?

I also want to know how I can stop numpy_1.8 from blocking 1.10. My initial thought was to remove numpy_1.8 using apt-get, but that would've removed many other packages that are dependent upon 1.8.

I'd be tempted to just use rm to get rid of the 1.8 version, but am worried that those other packages would be affected.

My second thought is to change sys.path to make certain the 1.10 version is seen before the 1.8 version. So far, I'm not using PYTHONPATH. Is there a way to change sys.path without using PYTHONPATH? Is this a reasonable approach to take?

网友答案:

The simplest thing to do is to remove your NumPy 1.8 installation. Look at numpy.__file__ to find where your 1.8 installation is, then delete the directory.

Alternatively, as you mentioned and if you don't want to delete 1.8, you could also change your path. Something like this ought to do it:

import sys
sys.path.insert(3, '<path_to_your_NumPy_1.10_install>')

I've inserted at position 3 so that you keep things like '' at the top, but you could modify this as needed.

分享给朋友:
您可能感兴趣的文章:
随机阅读: