我使用 pip 将库“numpy1.11.0”、“pandas0.18.1”、“scipy0.17.1”安装到站 pip 包中。问题是,当我在项目中导入 numpy 和 scipy 时,导入的是也已安装的旧版本,而不是新版本:
import numpy as np
import pandas as pd
import scipy as sc
print(np.__version__)
print(np.__file__)
print(pd.__version__)
print(pd.__file__)
print(sc.__version__)
print(sc.__file__)
output:
1.8.0rc1
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/__init__.pyc
0.18.1
/Library/Python/2.7/site-packages/pandas/__init__.pyc
0.13.0b1
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/__init__.pyc
由于只安装了一个pandas,所以可以正确导入最新版本。
python 和 site-packages 都有 numpy 和 scipy。
如何解决这个问题,谢谢!
最佳答案
您可以使用virtualenv ,在您想要的版本中安装您想要的库。
关于Python导入旧版本包而不是新版本包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37738530/