1

Recently I created my first package called pycohort: https://pypi.org/project/pycohort/

Here there are existing python functions that are working without any issues. A snippet from the code looks like this:

# packages needed
import pandas as pd
import numpy as np

def calculate_mean(some_list):

    """Function to calculate the mean of the data set.
    Returns: 
        float: mean of the data set
    """

    return (1.0 * sum(some_list) / len(some_list))

I first pip install pycohort and then import pycohort. When I call the above mentioned function like pycohort.calculate_mean(df.col1), I get the error message: AttributeError: module 'pycohort' has no attribute 'calculate_mean'.

While uploading the function, I navigated to my current working directory and then entered the below code. But I don't suspect that there is an issue here since I was able to upload and pip install successfully.

python setup.py sdist
pip install twine
twine upload dist/*

What am I missing here about uploading or calling the function?

Thanks for the help,

realkes
  • 833
  • 1
  • 12
  • 20
  • 1
    You've uploaded a broken package: the file `pycohort/__init__.py` in the package is zero length. Nothing can be imported from it. Fix the your packaging process, increase version and upload a new distribution. Use [TestPyPI](https://test.pypi.org/) to upload test packages. – phd Jun 08 '21 at 17:24
  • Thanks for looking into it. How should I fill the init file? Simply adding `import pycohort` will be enough? – realkes Jun 08 '21 at 17:34
  • You need to provide some code in your `pycohort/__init__.py`, code that implements functions for other code to import. – phd Jun 08 '21 at 17:35
  • Then the `init` file should include `from pycohort import ` for all functions? – realkes Jun 08 '21 at 17:37
  • `pycohort/__init__.py` should include the functions itself. Where from you gonna import them? `from pycohort import` imports from `pycohort.py` or from `pycohort/__init__.py`. – phd Jun 08 '21 at 18:54
  • I thought adding the functions only to `pycohort.py` would be enough but will add them to the `init` file as well. Thanks for your answer! – realkes Jun 08 '21 at 21:32
  • You shouldn't have both `pycohort.py` and `pycohort/__init__.py`. Use one or the other, not both. `import` cannot import from both. – phd Jun 08 '21 at 21:34

0 Answers0