Search code examples
piptravis-cipython-3.6pyyaml

Unable to import yaml (pyyaml) on travis-ci using python 3.6


I'm trying to test a python project which utilizes the yaml package (pyyaml) using travis-ci.

sudo: required
python: "3.6"
before_install:
  - sudo apt-get install -y python3-pip
  - sudo pip3 install pyyaml 
script:
  - ./setup.py test

However travis keeps giving me:

ModuleNotFoundError: No module named 'yaml'

I've tried using plain pip to install pyyaml, as well as the ubuntu package python3-yaml with no luck. I can get it to work on a local VM with ubuntu, just not in travis-ci.


Solution

  • The "ModuleNotFoundError" indicates that it is indeed Python 3.6 that generates the error Python <= 3.5 would give a module error. I would tend to use /path/to/python setup.py test, but it already looks like you have the right Python there.

    That leaves that pip3 might not install where you think it installs, so you should at least do:

    - sudo /path/to/python36 -m pip install pyyaml
    

    to make sure you get the pip3 that you are expecting, and that you are not using some default system Python 3.5 or earlier.

    You could also consider installing virtualenv with a known path, and install pyyaml in there and then run your setup.py with a full path of the python from there.