猿问

Travis CI Python 无法导入“请求”

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


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


我的脚本依赖于requests模块,我将其添加到requirements.txt文件中,然后 pip 将其安装在 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


三国纷争
浏览 161回答 1
1回答

MMTTMM

您需要专门调用python3 <filename>以确保您使用的是python3。我不确定为什么会发生这种情况,但显然该#!/usr/bin/python3指令不足以加载正确的模块。
随时随地看视频慕课网APP

相关分类

Python
我要回答