Using my package throws ModuleNotFoundError: No module named 'my-package' in Travis

被刻印的时光 ゝ 提交于 2019-12-24 06:51:08

问题


I am trying to use Travis CI for continuous integration but have been dealing with a lot of issues since it is my first time with Travis. Lately, I am running in to the following build fail:

ModuleNotFoundError: No module named 'my-package'

Which happens when in the following line of code in my db.py file:

import importlib
db_conf = importlib.import_module("my-package.conf.db_conf")

I should mention that I am using importlib since my repository has dashes in its name and based on suggestion in this post, I started using that package.

Right now, my project structure looks like the following:

my-project
├── conf
├───── db_conf.py
├── lib
└───── db.py

So as you can see I am trying to import db_conf.py from conf directory and running into no module named issue. I have been stuck with this for the past couple of days and have found the following posts on it: this one and this one. Problem is that I have tried all those methods and none of them seems to be working for me. Here is how my .travis.yml and setup.py files look like:

.travis.yml

language: python
python:
  - 3.7
env:
  global:
    # TRAVIS TESTING CONFIGURATION
    - COMMIT=${TRAVIS_COMMIT::8}
    - CGO_ENABLED=0
    - GOOS=linux
    - GOARCH=amd64
before_script:
  - export PYTHONPATH=$PYTHONPATH:$(pwd)
before_install:
  - python --version
  - pip install -U pip
  - python setup.py install
  - pip install -U pytest
  - pip install codecov
install:
  - pip install ".[test]" . # install package + test dependencies
script:
  - pytest
  - codecov
after_success:
  - codecov

And setup.py:

from setuptools import setup, find_packages

INSTALL_REQUIRES = [
    'pandas',
    'pyspark',
    'pyhdfs',
    'sqlalchemy',
    'configparser',
    'python-dotenv',
    'mysqlclient'
]
TEST_REQUIRES = [
    # testing and coverage
    'pytest', 'coverage', 'pytest-cov',
    # to be able to run `python setup.py checkdocs`
    'collective.checkdocs', 'pygments',
]

with open('README.md') as f:
    README = f.read()

setup(
    author="John Doe",
    author_email="john.doe@gmail.com",
    name='my-package',
    license="MIT",
    description='Supports my processes',
    version='1.0.0',
    long_description=README,
    url='https://github.com/my-user-name/my-package',
    packages=find_packages(),
    include_package_data=True,
    python_requires=">=3.5",
    install_requires=INSTALL_REQUIRES,
    extras_require={
        'test': TEST_REQUIRES + INSTALL_REQUIRES,
    },
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Programming Language :: Python',
        'Programming Language :: Python :: 3.7',
        'Topic :: Software Development :: Build Tools',
        'Intended Audience :: Developers',
    ],
)

Is there anything that I am missing here? Am I doing something wrong? Any help or any lead to the right direction is much appreciated because this is driving me nuts.

来源:https://stackoverflow.com/questions/57661399/using-my-package-throws-modulenotfounderror-no-module-named-my-package-in-tra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!