Dan*_*lan 17 python scipy travis-ci
我是第一次成立Travis-CI.我以我认为的标准方式安装scipy:
language: python
python:
- "2.7"
# command to install dependencies
before_install:
- sudo apt-get -qq update
- sudo apt-get -qq install python-numpy python-scipy python-opencv
- sudo apt-get -qq install libhdf5-serial-dev hdf5-tools
install:
- "pip install numexpr"
- "pip install cython"
- "pip install -r requirements.txt --use-mirrors"
# command to run tests
script: nosetests
Run Code Online (Sandbox Code Playgroud)
一切都在建立.但是当测试开始时,我得到了
ImportError: No module named scipy.ndimage
Run Code Online (Sandbox Code Playgroud)
更新:这是一个更直接的问题演示.
$ sudo apt-get install python-numpy python-scipy python-opencv
$ python -c 'import scipy'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named scipy
The command "python -c 'import scipy'" failed and exited with 1 during install.
Run Code Online (Sandbox Code Playgroud)
我也尝试使用pip安装scipy.我先尝试安装gfortran.以下是构建失败的一个示例.有什么建议?
另一个更新:特拉维斯已经添加了与Travis一起使用conda的官方文档.请参阅ostrokach的回答.
Dan*_*lan 13
我找到了解决这个难题的两种方法:
正如@unutbu建议的那样,构建自己的虚拟环境并在该环境中使用pip安装所有内容.我让构建通过,但是从源代码安装scipy非常慢.
按照ptraas项目在此.travis.yml文件中使用的方法以及它调用的shell脚本,强制travis使用系统范围的站点包,并使用apt-get安装numpy和scipy.这要快得多.关键是
virtualenv:
system_site_packages: true
Run Code Online (Sandbox Code Playgroud)
在组之前的travis.yml中before_install,后跟这些shell命令
SITE_PKG_DIR=$VIRTUAL_ENV/lib/python$TRAVIS_PYTHON_VERSION/site-packages
rm -f $VIRTUAL_ENV/lib/python$TRAVIS_PYTHON_VERSION/no-global-site-packages.txt
Run Code Online (Sandbox Code Playgroud)
然后最后
apt-get install python-numpy
apt-get install python-scipy
Run Code Online (Sandbox Code Playgroud)
当nosetests尝试导入它们时会找到它.
更新
我现在更喜欢基于conda的构建,它比上述任何一种策略都要快.这是我维护的项目的一个例子.
官方conda文档中对此进行了介绍:使用带有Travis CI的conda.
该
.travis.yml文件下面显示了如何修改
.travis.yml文件以将Miniconda用于支持Python 2.6,2.7,3.3和3.4的项目.注意:有关Travis 基本配置的信息,请参阅Travis CI网站.
language: python
python:
# We don't actually use the Travis Python, but this keeps it organized.
- "2.6"
- "2.7"
- "3.3"
- "3.4"
install:
- sudo apt-get update
# We do this conditionally because it saves us some downloading if the
# version is the same.
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
fi
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
# Useful for debugging any issues with conda
- conda info -a
# Replace dep1 dep2 ... with your dependencies
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION dep1 dep2 ...
- source activate test-environment
- python setup.py install
script:
# Your test script goes here
Run Code Online (Sandbox Code Playgroud)