2

I followed this article to create a python package.

https://packaging.python.org/tutorials/packaging-projects/

I created a new project and set up a new virtual environment. Instead of uploading it to pip and installing it from there i installed it from my local file system with:

python -m pip install path/to/.whl

retrieving the message: Installing collected packages: alexs-utils Successfully installed alexs-utils

I am not able to import my function from my_utils

This is my setup.py:

import setuptools

with open("README.md", "r") as fh:
    long_description = fh.read()

setuptools.setup(
    name="alexs_utils",
    version="0.0.1",
    author="Example Author",
    author_email="author@example.com",
    description="A small example package",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/pypa/my_utils",
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
    py_modules=['my_utils']
)

This is my my_utils.py:

def foo():
    print('bar')

This is my init.py:

name = "example_pkg"
Fu De
  • 21
  • 2
  • Your issue is that you do not add `utils.py` to the distribution; do that by adding `py_modules=['utils']` to the `setup()` arguments. The answer in the linked question has also an example for that. – hoefling Aug 07 '19 at 12:03
  • on a note they did not do this in this explaination as well : https://packaging.python.org/tutorials/packaging-projects/ But i tried it out and iam still not able to import This is not a duplicate. – Fu De Aug 07 '19 at 12:12
  • _i created a folder with a LICENSE, README.md, setup.py and utils.py_ means that you have the `utils.py` as the standalone module. If you want to put it in a wheel, you have to include it via `py_modules`. I have tested the project setup locally and adding `py_modules` solves the issue, the code `from utils import stuff` works fine after the wheel rebuild and installation. – hoefling Aug 07 '19 at 12:19
  • _on a note they did not do this in this explaination as well_ because their example includes a package, not a standalone module. – hoefling Aug 07 '19 at 12:20

0 Answers0