skip to Main Content

When I install one of my own Python applications from PyPi, it fails to run citing

File "/home/me/.local/lib/python3.9/site-packages/refrapt/refrapy.py", line 20, in
from classes import (
ModuleNotFoundError: No module named ‘classes’.

I have the following directory layout in my local area:

/refrapt
  setup.py
  /refrapt
    classes.py
    helpers.py
    refrapt.conf
    refrapt.py
    settings.py
    __init__.py

To build the project, I’m using setuptools, running the following command:
python setup.py sdist bdist_wheel
This builds and works happily enough, and I’m able to upload the resulting /dist.

I then install the project using pip3 install refrapt. When I run it using refrapt, I get the error ModuleNotFoundError above.

When I run the development code locally, it runs fine, but installed via pip, it is failing. I assume it’s a problem with my setup.py, but this is my first time and I haven’t really a clue what is correct. I tried adding the init.py (which is empty) as suggested by some python docs, but to no avail. The contents of setup.py are as follows:

import pathlib
from setuptools import setup, find_packages

HERE = pathlib.Path(__file__).parent

README = (HERE / "README.md").read_text()

setup(
    name='Refrapt',
    version='0.1.5',
    description='A tool to mirror Debian repositories for use as a local mirror.',
    python_requires='>=3.9',
    long_description=README,
    long_description_content_type="text/markdown",
    packages=find_packages(),
    install_requires=[
        'Click >= 7.1.2',
        'Colorama >= 0.4.4',
        'tqdm >= 4.60.0',
        'wget >= 3.2',
        'filelock >= 3.0.12'
    ],
    classifiers=[
        "Development Status :: 4 - Beta",
        "Operating System :: Microsoft :: Windows :: Windows 10",
        "Operating System :: POSIX :: Linux",
        "Programming Language :: Python :: Implementation",
        "Topic :: System :: Archiving :: Mirroring"
    ],
    keywords=['Mirror', 'Debian', 'Repository'],
    entry_points='''
        [console_scripts]
        refrapt=refrapt:refrapt
    ''',
)

If anyone could help, I’d greatly appreciate. I’m out of my depth on this one, and haven’t been able to find an answer so far.

2

Answers


  1. Chosen as BEST ANSWER

    Potentially I've found out the answer to my question, but it's not the answer I wanted.

    I spun up a virtual environment, and installed an application that I've used before via pip. When I went to run the app, I got the ModuleNotFoundError: No module named 'app'.

    I tried to run it manually via the .py file by using python ..venvLibsite-packagesappcli.py, which resulting in the same error.

    Seems to be something about the environment setup in Windows VS Code that just doesn't operate the same as on a Linux machine.

    I guess I'll just have to remove the "refrapt." prefix from import statements when developing locally, and then add it back when pushing to GitHub.


  2. from classes import …
    

    In Python 2 this was relative import — the statements imports classes from the current directory of the importing module.

    But in Python 3 it was changed to absolute import. The import fails because there is no a global module or a package named classes. You need to convert the import to absolute or relative. Either

    from refrapt.classes import …
    

    or

    from .classes import …
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search