簡體   English   中英

travis-ci上的scipy ImportError

[英]scipy ImportError on 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

一切都在建立。 但是當測試開始時,我得到了

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。 以下是構建失敗的一個示例 有什么建議?

另一個更新 :特拉維斯已經添加了與Travis一起使用conda的官方文檔。 請參閱ostrokach的回答。

我找到了解決這個難題的兩種方法:

  1. 正如@unutbu建議的那樣,構建自己的虛擬環境並在該環境中使用pip安裝所有內容。 我讓構建通過,但是從源代碼安裝scipy非常慢。

  2. 按照ptraas項目在此.travis.yml文件中使用的方法以及它調用的shell腳本 ,強制travis使用系統范圍的站點包,並使用apt-get安裝numpy和scipy。 這要快得多。 關鍵是

     virtualenv: system_site_packages: true 

    在before_install組之前的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 

    然后最后

     apt-get install python-numpy apt-get install python-scipy 

    當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

我發現這種方法有效:

http://danielnouri.org/notes/2012/11/23/use-apt-get-to-install-python-dependencies-for-travis-ci/

將這些行添加到Travis配置中以使用帶有--system-site-packagesvirtualenv

virtualenv:
  system_site_packages: true

因此,您可以在before_install部分中通過apt-get安裝Python包,並在virtualenv中使用它們:

before_install:
 - sudo apt-get install -qq python-numpy python-scipy

nolearn中可以找到這種方法的實際用途。

正如Dan Allan在他的更新中指出的,他現在更喜歡基於conda的構建。 這里有一個要點禮貌丹查德給全.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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM