我是第一次成立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
一切都在建立。但是当鼻子测试开始时,我得到了
ImportError: No module named scipy.ndimage
更新:以下是此问题的更直接演示。
$ 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.
我也尝试使用pip安装scipy。我先尝试安装gfortran。 Here is one example of a failed build。有什么建议吗?
另一个更新:Travis此后添加了有关使用带有Travis的conda的官方文档。请参阅ostrokach的回答。
答案 0 :(得分:13)
我找到了解决这个难题的两种方法:
正如@unutbu建议的那样,构建自己的虚拟环境并在该环境中使用pip安装所有内容。我让构建通过,但是从源代码安装scipy非常慢。
按照this .travis.yml file and the shell scripts that it calls中pandas项目使用的方法,强制travis使用系统范围的站点包,并使用apt-get安装numpy和scipy。这要快得多。关键线是
virtualenv:
system_site_packages: true
在before_install
组之前的travis.yml中,然后是这些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
然后最后
apt-get install python-numpy
apt-get install python-scipy
将在nosetests尝试导入它们时找到。 <强>更新强>
我现在更喜欢基于conda的构建,这比上述任何一种策略都要快。这是我维护的项目的one example。
答案 1 :(得分:5)
官方conda文档中对此进行了介绍:Using conda with Travis CI。
.travis.yml
文件以下显示了如何修改
的信息,请参阅Travis CI网站.travis.yml
文件以使用Miniconda来支持Python 2.6,2.7,3.3和3.4的项目。
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
答案 2 :(得分:4)
我发现这种方法有效:
http://danielnouri.org/notes/2012/11/23/use-apt-get-to-install-python-dependencies-for-travis-ci/
将这些行添加到Travis配置中,以
virtualenv
与--system-site-packages
一起使用:
virtualenv:
system_site_packages: true
您可以在
apt-get
部分通过before_install
安装Python软件包,并在您的virtualenv中使用它们:
before_install:
- sudo apt-get install -qq python-numpy python-scipy
可以在nolearn中找到这种方法的实际用途。
答案 3 :(得分:1)
正如Dan Allan在他的更新中指出的,他现在更喜欢基于conda的构建。 Here is a gist由Dan Blanchard提供完整的.travis.yml
文件示例,该示例将在测试计算机上预安装scipy:
language: python
python:
- 2.7
- 3.3
notifications:
email: false
# Setup anaconda
before_install:
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
- chmod +x miniconda.sh
- ./miniconda.sh -b
- export PATH=/home/travis/miniconda/bin:$PATH
- conda update --yes conda
# The next couple lines fix a crash with multiprocessing on Travis and are not specific to using Miniconda
- sudo rm -rf /dev/shm
- sudo ln -s /run/shm /dev/shm
# Install packages
install:
- conda install --yes python=$TRAVIS_PYTHON_VERSION atlas numpy scipy matplotlib nose dateutil pandas statsmodels
# Coverage packages are on my binstar channel
- conda install --yes -c dan_blanchard python-coveralls nose-cov
- python setup.py install
# Run test
script:
- nosetests --with-cov --cov YOUR_PACKAGE_NAME_HERE --cov-config .coveragerc --logging-level=INFO
# Calculate coverage
after_success:
- coveralls --config_file .coveragerc