Python3 module import fails on Travis ci

前端 未结 1 940
野趣味
野趣味 2021-01-12 18:55

I have made a Python 3 script for testing a project of mine. The script has this structure:

main.py
myRequest.py
external/
  requests/
    __init__.py
    ma         


        
1条回答
  •  北海茫月
    2021-01-12 19:50

    I encountered the same issue, so I am posting here in hope to help somebody:

    Quick Fix

    The quick fix for me was to add this line export PYTHONPATH=$PYTHONPATH:$(pwd) in the .travis.yml:

    before_install:
      - "pip install -U pip"
      - "export PYTHONPATH=$PYTHONPATH:$(pwd)"
    

    Have a setup.py

    Having a setup.py which should be the default option as it is the most elegant. With that you would resolve your relative import issue, try one configured like:

    from setuptools import setup, find_packages
    
    setup(name='MyPythonProject',
          version='0.0.1',
          description='What it does',
          author='',
          author_email='',
          url='',
          packages=find_packages(),
         )
    

    And then add this line in .travis.yml

    before_install:
      - "pip install -U pip"
      - "python setup.py install
    

    0 讨论(0)
提交回复
热议问题