3

I've got a very simple wheel file I'm building, which seems to build okay, but it relies on a separate config.py module that is called upon import, which is failing after pip installing the wheel file.

Research done: Building a python wheel : "no module named ______" (I can't discern where I'm deviating from that advice)

Project structure:

/easypki
    /easypki
        /__init__.py
        /config.json
        /config.py
        /easypki.py
   README.md
   setup.py

Contents of __init__.py:

#!/usr/bin/python3
__version__ = "0.1"

from . easypki import EasyPKI  # main class
from . config import Config  # configuration class

Contents of setup.py:

import pathlib
from setuptools import setup, find_packages

__here__ = pathlib.Path(__file__).parent
README = (__here__ / "README.md").read_text()

setup(
    name="easypki",
    version="0.1",
    description="Even simpler client PKI cert interface",
    long_description=README,
    long_description_content_type="text/markdown",
    url="https://wherever",
    author="me",
    author_email="my@email.com",
    license="MIT",
    classifiers=[
            "License :: OSI Approved :: MIT License",
            "Programming Language :: Python :: 3",
            "Programming Language :: Python :: 3.7"
    ],
    packages=find_packages(),
    include_package_data=True,
    install_requires=["requests", "requests_pkcs12"],
)

I am almost 100% sure that I'm going wrong in __init__.py but am having trouble figuring out exactly what needs changed.

EDIT: adding full error message:

>>> import easypki
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\easypki\__init__.py", line 7, in <module>
    from . easypki import EasyPKI
  File "C:\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\easypki\__init__.py", line 2, in <module>
    from config import Config
ModuleNotFoundError: No module named 'config'

EDIT 2:

I ended up getting this working, however I'm not entirely sure why. I believe it has something to do with how the import call to the config.Config class was being made from within easypki.py:

from config import Config

So I did a couple things:

  1. I moved the config.Config import call to within easypki.EasyPKI __init__() method.
  2. I switched the import call to from .config import Config
  3. I removed the line from .config import Config from __init__.py as the config.Config class is not (yet) meant to be set directly but is just reading whatever's in config.json.
auslander
  • 507
  • 2
  • 5
  • 14
  • Can you include the full error message. – John Gordon Nov 15 '21 at 21:31
  • @JohnGordon done. – auslander Nov 15 '21 at 21:43
  • The error message has `from config import Config`, but the code sample has `from . config import Config`. Which is it? – John Gordon Nov 15 '21 at 22:21
  • @JohnGordon I edited/updated a bit more. I *think* I got a little vertigo because I was importing the `Config` class from within `easypki.py`. As I don't want/need to expose the Config class succinctly, I just dropped it from `__init__.py` and edited the import call with a relative path prefix. Not sure I could explain why it all ended up working, but it did. – auslander Nov 15 '21 at 22:25

0 Answers0