我有一个scipy作为依赖的包。我已经知道通过apt-get
安装scipy给了我们一个过时的软件包版本,并且通过pip
安装它超过了Travis VM,因此我决定在测试期间下载并安装Miniconda,比如在许多其他问题中提出。
但是,每当我推送到GitHub并且Travis运行我的单元测试时,它都无法找到scipy
包。错误消息只是ImportError: No module named 'scipy'
。
以下是我的.travis.yml
文件的内容。 python --version
正确指向“Python 3.4.4 :: Continuum Analytics,Inc。”并且conda list
显示安装了scipy 0.17.0。如果有人有兴趣,这里是full log of my Travis build。
language: python
python:
# We don't actually use the Travis Python, but this keeps it organized.
- "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
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy scipy scikit-learn matplotlib
- source activate test-environment
- conda list
- python --version
- whereis python
- python setup.py install
script: nosetests
答案 0 :(得分:1)
您的python与travis日志中显示的虚拟环境不对应。我猜是nosetests
正在使用自己的venv。
所以看看nosetests
:它可能有一个不同的,硬编码的shebang作为第一行(head -n1 $(which nosetests)
可能会这样做),因此使用不同的python和不同的venv。
如果以上是正确的,解决方案可能是安装自己的nosetests版本。这应该优先考虑(在你的PATH中更早)。