Home > Software engineering >  Python package Module not found errors
Python package Module not found errors

Time:10-20

I made a python package whose setup.py looks like this

from setuptools import setup, find_packages
setup(
    name='sc_eol',
    version='0.0.1',
    description="SC EOL API",
    packages=find_packages(),
    package_data={
        x: ['*.csv', '*.json', '*.txt', '*.sql', '*.yml', '*.cfg']
        for x in find_packages()
    },
    url="mmmmmm.com",
    install_requires=[line for line in open('requirements.txt')],
    author="Shivangi Singh",
    author_email="[email protected]",
    include_package_data=True,
    options={"bdist_wheel": {"universal": True}},
    python_requires=">=3.8",
    entry_points={
        'console_scripts': [
            'server=sc_eol.server:main',
        ]
    }
)

my directory structure looks like this

enter image description here

In the test-server.py I try to import the server like from sc_eol.server import server and run the tests like.

#! /bin/bash
export PYTHONPATH="/home/ubuntu/sc-eol/sc-eol" 
pytest -s -v  tests/ 

I get the following error.

___________________________________________________________ ERROR collecting tests/test_server.py ___________________________________________________________
ImportError while importing test module '/home/ubuntu/sc-eol/tests/test_server.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_server.py:3: in <module>
    from sc_eol.server import server
E   ModuleNotFoundError: No module named 'sc_eol'

Also, I have tried installing the package via pip install -e . and I get an error package not found.

CodePudding user response:

In your test file:

#! /bin/bash
export PYTHONPATH="/home/ubuntu/sc-eol/sc-eol" 
pytest -s -v  tests/ 

I believe that your PYTHONPATH is too deep. Can you try this:

#! /bin/bash
export PYTHONPATH="/home/ubuntu/sc-eol" 
pytest -s -v  tests/

CodePudding user response:

I needed to rename my folders with _

  • Related