如何在 virtualenv 中的 Python 2.7 上安装 numpy?

如何在 virtualenv 中的 Python 2.7 上安装 numpy?

我正在尝试在(Cygwin 上) 安装。numpy但是 ,当我尝试时,我收到:Python 2.7virtualenv
import numpyImportError

Administrator@Ron ~/python/virtualenv
$ virtualenv -p /usr/bin/python2.7.exe machine_learning
Running virtualenv with interpreter /usr/bin/python2.7.exe
New python executable in /home/Administrator/python/virtualenv/machine_learning/bin/python2.7
Also creating executable in /home/Administrator/python/virtualenv/machine_learning/bin/python
Installing setuptools, pip, wheel...done.

Administrator@Ron ~/python/virtualenv
$ source machine_learning/bin/activate
(machine_learning)
Administrator@Ron ~/python/virtualenv
$ pip2 install numpy
Collecting numpy
Installing collected packages: numpy
Successfully installed numpy-1.13.0
(machine_learning)
Administrator@Ron ~/python/virtualenv
$ python2 -c "import numpy"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/Administrator/python/virtualenv/machine_learning/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/home/Administrator/python/virtualenv/machine_learning/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/Administrator/python/virtualenv/machine_learning/lib/python2.7/site-packages/numpy/lib/__init__.py", line 19, in <module>
    from .polynomial import *
  File "/home/Administrator/python/virtualenv/machine_learning/lib/python2.7/site-packages/numpy/lib/polynomial.py", line 20, in <module>
    from numpy.linalg import eigvals, lstsq, inv
  File "/home/Administrator/python/virtualenv/machine_learning/lib/python2.7/site-packages/numpy/linalg/__init__.py", line 51, in <module>
    from .linalg import *
  File "/home/Administrator/python/virtualenv/machine_learning/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 30, in <module>
    from numpy.linalg import lapack_lite, _umath_linalg
ImportError: No such file or directory
(machine_learning)
Administrator@Ron ~/python/virtualenv

关于如何在 virtualenv 中的 Python 2.7 上安装 numpy 有什么建议吗?

注意:
Cygwin的Python3版本是3.6,而pypi numpy似乎还没有准备好3.6。

编辑1:

回答马策里的评论,我卸载了numpypip3 和 pip2,并numpy从 Cygwin 的 setup.exe 安装了 Python 3 和 Python 2。
以下是我在尝试导入 numpy 时遇到的错误:

$ python3 -c "import numpy"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/usr/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/lib/python3.6/site-packages/numpy/lib/__init__.py", line 18, in <module>
    from .polynomial import *
  File "/usr/lib/python3.6/site-packages/numpy/lib/polynomial.py", line 20, in <module>
    from numpy.linalg import eigvals, lstsq, inv
  File "/usr/lib/python3.6/site-packages/numpy/linalg/__init__.py", line 51, in <module>
    from .linalg import *
  File "/usr/lib/python3.6/site-packages/numpy/linalg/linalg.py", line 29, in <module>
    from numpy.linalg import lapack_lite, _umath_linalg
ImportError: No such file or directory

$ python2 -c "import numpy"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/usr/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/lib/python2.7/site-packages/numpy/lib/__init__.py", line 18, in <module>
    from .polynomial import *
  File "/usr/lib/python2.7/site-packages/numpy/lib/polynomial.py", line 20, in <module>
    from numpy.linalg import eigvals, lstsq, inv
  File "/usr/lib/python2.7/site-packages/numpy/linalg/__init__.py", line 51, in <module>
    from .linalg import *
  File "/usr/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 29, in <module>
    from numpy.linalg import lapack_lite, _umath_linalg
ImportError: No such file or directory

答案1

使用 cygwin 设置安装该软件包python2-numpy。您不需要 pip 来安装它。

python2 -c "import numpy"对我有用。
由于问题似乎lapack_lite出在检查您/usr/lib/lapack/的路径上。

$ cygcheck -l liblapack0
/etc/profile.d/lapack0.csh
/etc/profile.d/lapack0.sh
/usr/lib/lapack/cygblas-0.dll
/usr/lib/lapack/cyglapack-0.dll


 $ cygcheck /usr/lib/python2.7/site-packages/numpy/linalg/lapack_lite.dll | grep -v Windows
E:\cygwin64\lib\python2.7\site-packages\numpy\linalg\lapack_lite.dll
  E:\cygwin64\bin\cygwin1.dll
  E:\cygwin64\lib\lapack\cyglapack-0.dll
    E:\cygwin64\bin\cyggcc_s-seh-1.dll
    E:\cygwin64\bin\cyggfortran-3.dll
      E:\cygwin64\bin\cygquadmath-0.dll
    E:\cygwin64\bin\cygblas-0.dll
  E:\cygwin64\bin\libpython2.7.dll

否则 lapack 库将无法运行。

相关内容