Travis CI Python无法导入“请求”

问题描述 投票:4回答:1

我想在Travis CI构建环境中运行一个简单的Python 3脚本。我按照Travis CI Python指南(https://docs.travis-ci.com/user/languages/python)创建了一个初始的.travis.yml文件。

Travis CI针对YML文件中描述的Python版本,在单独的virtualenv中运行每个构建。

我的脚本依赖于requests模块,我将其添加到requirements.txt文件中并将其安装在Travis CI中,但是一旦脚本运行,脚本就无法导入模块。

错误

./benchmark.py https://graph.irail.be/sncb/connections -n 10 -i -o results.csv
Traceback (most recent call last):
File "./benchmark.py", line 3, in <module>
   import requests
ImportError: No module named 'requests'

.travis.yml

language: python
python:
   - "3.3"
   - "3.4"
   - "3.5"
   - "3.6"
# command to install deps
install:
   - pip install -r requirements.txt

# run build
script:
   - ./benchmark.py https://graph.irail.be/sncb/connections -n 10 -i -o results.csv

我的Github回购:https://github.com/DylanVanAssche/http-benchmark/tree/feature/CI

我的Travis CI版本:https://travis-ci.com/DylanVanAssche/http-benchmark/jobs/145320050

python python-requests travis-ci
1个回答
2
投票

您需要专门调用python3 <filename>以确保您使用的是python3。我不确定为什么会这样,但显然#!/usr/bin/python3指令不足以加载适当的模块。

© www.soinside.com 2019 - 2024. All rights reserved.