Top Rated on Upwork with a 100% Job Success ScoreView on Upwork
retzdev logo
logo
Building a Python Package

Building a Python Package: First Release (6)

by Jarrett Retz

February 27th, 2021

    Introduction

    I wanted to publish a first release for the package but ran into problems after installing and importing the package.

    After running through a few more test alpha releases I was able to make a couple of adjustments and eventually install and use the package as intended.

    Additionally, I forgot to import all the new table definitions into the main Bea class.

    Setup Files

    In the last post I removed the setup.py file and only had the setup.cfg in the project. When I tested the package, I may have still been using the local version, and therefore the package was still working.

    Before the first release, I wanted to test the client from a new virtual environment. When I downloaded and tried to import the Bea client I got a "Module Not Found" error.

    Reviewing the packaging python projects guide I noticed that the example project had both the setup.py and setup.cfg file.

    Therefore, I added both files to the project (after trying a couple of different configurations). That solved the import error, but then I started receiving an import error for tables.py.

    Relative Import Error

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Users/jarrettretz/venv/lib/python3.9/site-packages/beasy/beasy.py", line 2, in <module>
        from .tables.tables import (
    ModuleNotFoundError: No module named 'beasy.tables'

    The folder configuration in the package had tables.py nested inside of the tables folder.

    It worked locally but failed when I installed it from PyPI. I couldn't solve the issue by keeping tables.py inside its own folder. I pulled it out of the folder and put it at the same level as beasy.py.

    I think I could have solved the issue by adding an __init__.py file to the tables folder, but I didn't want to put in the effort because it wasn't important to the project that tables.py was in its own folder.

    After changing the import statement in beasy.py I rebuilt the package, published it to PyPI, installed the newest version, and was able to use the package as intended.

    You can visit the first release of beasy on PyPI at https://pypi.org/project/beasy/

    You can see the source code for beasy on Github at https://github.com/jdretz/simple-bea-client

    Jarrett Retz

    Jarrett Retz is a freelance web application developer and blogger based out of Spokane, WA.

    jarrett@retz.dev

    Subscribe to get instant updates

    Contact

    jarrett@retz.dev

    Legal

    Any code contained in the articles on this site is released under the MIT license. Copyright 2022. Jarrett Retz Tech Services L.L.C. All Rights Reserved.