Reputation: 540
I would like to run a simple Python 3 script in the Travis CI build environment.
I followed the Travis CI Python guide (https://docs.travis-ci.com/user/languages/python) to create an initial .travis.yml
file.
Travis CI runs each build in a separate virtualenv against the Python versions described in the YML file.
My script depends on the requests
module, I added it to the requirements.txt
file and pip installs it in Travis CI, but as soon as the script runs, the script can't import the module.
error
./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
My Github repo: https://github.com/DylanVanAssche/http-benchmark/tree/feature/CI
My Travis CI build: https://travis-ci.com/DylanVanAssche/http-benchmark/jobs/145320050
Upvotes: 4
Views: 671
Reputation: 226
You need to specifically call python3 <filename>
to make sure you're using python3. I'm not sure why this happens but apparently the #!/usr/bin/python3
directive is not sufficient to load the proper modules.
Upvotes: 2