Using my package throws ModuleNotFoundError: No mo

2019-08-28 18:05发布

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.

0条回答
登录 后发表回答