简体   繁体   English

在Amazon EC2上安装numpy

[英]Installing numpy on Amazon EC2

I am having trouble installing numpy on an Amazon EC2 server. 我在Amazon EC2服务器上安装numpy时遇到问题。 I have tried using easy_install, pip, pip inside a virtual env, pip inside another virtual env using python 2.7... 我尝试在虚拟环境中使用easy_install,pip,pip,使用python 2.7在另一个虚拟环境中进行pip ...

Every time I try, it fails with the error: gcc: internal compiler error: Killed (program cc1) , and then further down the line I get a bunch of python errors, with easy_install I get: ImportError: No module named numpy.distutils , and with pip I get: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 72: ordinal not in range(128) . 每次我尝试,它都会失败并出现错误: gcc: internal compiler error: Killed (program cc1) ,然后再下线我得到一堆python错误,我得到easy_install: ImportError: No module named numpy.distutils ,并使用pip我得到: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 72: ordinal not in range(128)

The EC2 instance is running kernel 3.4.43-43.43.amzn1.x86_64. EC2实例正在运行内核3.4.43-43.43.amzn1.x86_64。 Has anybody solved this problem? 有人解决了这个问题吗? Numpy has always been hard for me to install, but I can usually figure it out... at this point I don't care whether it is in it's own virtualenv, I just want to get it installed. Numpy对我来说一直很难安装,但我通常可以搞清楚......在这一点上我并不关心它是否属于它自己的virtualenv,我只想安装它。

Requirements for installing Numpy 安装Numpy的要求

  • c compiler (gcc) c编译器(gcc)
  • fortran compiler (gfortran) fortran编译器(gfortran)
  • python header files (2.4.x - 3.2.x) python头文件(2.4.x - 3.2.x)
  • Strongly recommended BLAS or LAPACK 强烈推荐BLAS或LAPACK

I wrote a script to install virtualenv and scikit-learn along with all the dependencies. 我编写了一个脚本来安装virtualenv和scikit-learn以及所有依赖项。 You can follow up to the numpy install, which is pretty straight forward. 您可以跟进numpy安装,这非常简单。 I copied the relevant code below. 我复制了下面的相关代码。

sudo yum -y install gcc-c++ python27-devel atlas-sse3-devel lapack-devel
wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.11.2.tar.gz
tar xzf virtualenv-1.11.2.tar.gz 
python27 virtualenv-1.11.2/virtualenv.py sk-learn
. sk-learn/bin/activate
pip install numpy

Just copy/paste, hit enter, (get a cup of coffee) and you're ready to go with virtualenv and numpy on EC2. 只需复制/粘贴,点击输入,(喝一杯咖啡),你就可以在EC2上使用virtualenv和numpy了。

If you want to verify that numpy found the optimized linear algebra libraries, run: 如果要验证numpy是否找到了优化的线性代数库,请运行:

(sk-learn)[ec2-user@ip-10-99-17-223 ~]$ python -c "import numpy; numpy.show_config()"

if you see something similar to the following you're all set. 如果您看到类似于以下内容的内容,那么您已经完成了设置。

atlas_threads_info:
    libraries = ['lapack', 'ptf77blas', 'ptcblas', 'atlas']
    library_dirs = ['/usr/lib64/atlas-sse3']
    define_macros = [('ATLAS_INFO', '"\\"3.8.4\\""')]
    language = f77
    include_dirs = ['/usr/include']
blas_opt_info:
    libraries = ['ptf77blas', 'ptcblas', 'atlas']
    library_dirs = ['/usr/lib64/atlas-sse3']
    define_macros = [('ATLAS_INFO', '"\\"3.8.4\\""')]
    language = c
    include_dirs = ['/usr/include']
atlas_blas_threads_info:
    libraries = ['ptf77blas', 'ptcblas', 'atlas']
    library_dirs = ['/usr/lib64/atlas-sse3']
    define_macros = [('ATLAS_INFO', '"\\"3.8.4\\""')]
    language = c
    include_dirs = ['/usr/include']
lapack_opt_info:
    libraries = ['lapack', 'ptf77blas', 'ptcblas', 'atlas']
    library_dirs = ['/usr/lib64/atlas-sse3']
    define_macros = [('ATLAS_INFO', '"\\"3.8.4\\""')]
    language = f77
    include_dirs = ['/usr/include']
lapack_mkl_info:
  NOT AVAILABLE
blas_mkl_info:
  NOT AVAILABLE
mkl_info:
  NOT AVAILABLE

For a more detailed explanation, you can read installing-scikit-learn-on-amazon-ec2 . 有关更详细的说明,请阅读安装-scikit-learn-on-amazon-ec2 I wrote the blog post specifically to remember the installation steps and have a short how-to guide. 我专门编写了博客文章来记住安装步骤,并有一个简短的操作指南。 I try to keep the post and the install script up to date. 我尝试使帖子和安装脚本保持最新。

I ended up just installing numpy through yum, sudo yum install numpy . 我最后只是通过yum安装numpy, sudo yum install numpy I guess this is the best I can do for now. 我想这是我现在能做的最好的事情。 When working with virtualenv and I need numpy, I will tell it to use site packages. 当使用virtualenv并且我需要numpy时,我会告诉它使用站点包。

Thanks for the suggestion @Robert. 感谢@Robert的建议。

Just for the archive. 只是为了存档。 If you are running an Ubuntu EC2 and you have already installed pip, then you can do something like: 如果您正在运行Ubuntu EC2并且您已经安装了pip,那么您可以执行以下操作:

for Python2: 对于Python2:

pip install numpy --user

for Python 3: 对于Python 3:

pip3 install numpy --user

the key is the word user . 关键是user这个词。

You might try using the Anaconda Python distribution from https://www.continuum.io , which uses the conda Python version and package manager. 您可以尝试使用https://www.continuum.io中的Anaconda Python发行版,它使用conda Python版本和包管理器。 I have found this distro to be well-configured and convenient for scientific computing work. 我发现这个发行版配置精良,便于科学计算工作。

I was able to download and install into an EC2 instance using wget and the linux download link from their Downloads webpage. 我可以使用wget和他们的下载网页上的linux下载链接下载并安装到EC2实例中。 For example, for Python 2: 例如,对于Python 2:

$ wget https://3230d63b5fc54e62148e-c95ac804525aac4b6dba79b00b39d1d3.ssl.cf1.rackcdn.com/Anaconda2-2.5.0-Linux-x86_64.sh $ wget https://3230d63b5fc54e62148e-c95ac804525aac4b6dba79b00b39d1d3.ssl.cf1.rackcdn.com/Anaconda2-2.5.0-Linux-x86_64.sh

... ...

$ chmod a+x Anaconda2-2.5.0-Linux-x86_64.sh $ chmod a + x Anaconda2-2.5.0-Linux-x86_64.sh

$ ./Anaconda2-2.5.0-Linux-x86_64.sh $ ./Anaconda2-2.5.0-Linux-x86_64.sh

... ...

$ source .bashrc $ source .bashrc

$ conda create --name myEnvName biopython $ conda create --name myEnvName biopython

$ source activate myEnvName $ source激活myEnvName

$ python -c 'import numpy; $ python -c'import numpy; print(numpy.version.version)' 打印(numpy.version.version)”

1.10.4 1.10.4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM