无法在生产服务器上安装SciPy

0 投票
3 回答
3248 浏览
提问于 2025-05-01 00:29

我正在云端的Ubuntu机器上安装SciPy。以下是我按照的步骤:

  • 首先用命令安装numpy:sudo pip install numpy
  • 然后安装gfortran:sudo apt-get install gfortran
  • 接着安装libblas-dev:sudo apt-get install libblas-dev
  • 再安装liblapack-dev:sudo apt-get install liblapack-dev
  • 然后安装g++:sudo apt-get install g++
  • 最后安装scipy:sudo pip install scipy

顺便说一下,我的系统是Ubuntu 14.04,Python版本是2.7.6。我没有安装Python,它本来就在机器上,pip和easy_install也是自带的。以下是pip的日志:

(.text+0x20): undefined reference to `main'

collect2: error: ld returned 1 exit status

/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':

(.text+0x20): undefined reference to `main'

collect2: error: ld returned 1 exit status

error: Command "/usr/bin/gfortran -Wall -g -L/opt/bitnami/common/lib -L/opt/bitnami/common/lib build/temp.linux-x86_64-2.7/numpy/core/blasdot/_dotblas.o -L/usr/lib
-L/opt/bitnami/python/lib -Lbuild/temp.linux-x86_64-2.7 -lopenblas -lpython2.7 -lgfortran -o build/lib.linux-x86_64-2.7/numpy/core/_dotblas.so" failed with exit status 1

----------------------------------------  
Cleaning up...   Removing temporary dir /tmp/pip_build_root... Command /opt/bitnami/python/bin/.python2.7.bin -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/numpy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-Lm8nxq-record/install-record.txt
    --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/numpy Exception information: 

Traceback (most recent call last):
File "/opt/bitnami/python/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 130, in main
    status = self.run(options, args)   File "/opt/bitnami/python/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)   File "/opt/bitnami/python/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 1435, in install
    requirement.install(install_options, global_options, *args, **kwargs)   File "/opt/bitnami/python/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 706, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)   File "/opt/bitnami/python/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/util.py", line 697, in call_subprocess
    % (command_desc, proc.returncode, cwd)) InstallationError: Command /opt/bitnami/python/bin/.python2.7.bin -c "import setuptools, tokenize;__file__='/tmp/pip_build_root/numpy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-Lm8nxq-record/install-record.txt
--single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_root/numpy

pip文件:

#!/opt/bitnami/python/bin/.python2.7.bin
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.5.6','console_scripts','pip'
__requires__ = 'pip==1.5.6' import sys from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
    )

easy_install文件:

#!/usr/bin/env /opt/bitnami/python/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'distribute==0.6.34','console_scripts','easy_install'
__requires__ = 'distribute==0.6.34' import sys from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('distribute==0.6.34', 'console_scripts', 'easy_install')()
    )

请帮帮我。

这是不是因为gfortran编译器的设置问题?我只是有这个怀疑。

暂无标签

3 个回答

0

这个问题还是没有解决,所以我把之前在 /opt/bitnami/python 上的自定义安装给删掉了,改用系统自带的安装,现在一切都正常了。

我使用下面的命令安装了 scipy 和 numpy:

sudo apt-get install python-numpy python-scipy
2

我通过修改这个环境变量,成功在bitnami上安装了numpy和scipy:

export LDFLAGS="-shared"

接下来安装scipy的步骤是:

sudo apt-get update -y
sudo apt-get install python-pip python-dev build-essential
sudo pip install numpy
sudo apt-get install libatlas-base-dev gfortran
sudo pip install scipy

参考numpy的问题

5

Ubuntu软件包

SciPy的手册 建议使用Ubuntu版本,而不是pip版本

sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose

pip

另一种方法是 安装所需的依赖项

sudo apt-get install python-pip python-dev build-essential
sudo pip install numpy
sudo apt-get install libatlas-base-dev gfortran
sudo pip install scipy

我刚在一台AWS的Ubuntu 14.04机器上测试过,经过很长的编译过程和很多警告,结果一切都正常。

我一般推荐使用后者,因为它可以在任何虚拟环境中工作,而前者则是全局安装软件包。

撰写回答