Home > database >  cant import python module I just made on github
cant import python module I just made on github

Time:02-14

I want to learn how to make my own collection of functions available to myself and my coworkers. After some reading I settled on making a python package, putting it on github and using pip install git https:// to make it available to my coworkers. We use anaconda by the way, not sure if it matters.

So I've made the following repository: https://github.com/accountname/reponame and in a fresh anaconda environment using:

conda create -n github_test python=3.9

I will install my package into it using:

pip install git https://github.com/accountname/reponame.git

This worked! Great! When I run conda list I get the following output:

# packages in environment at C:\Users\MyName\anaconda3\envs\github_test:
#
# Name                    Version                   Build  Channel
ca-certificates           2021.10.26           haa95532_4
certifi                   2021.10.8        py39haa95532_2
openssl                   1.1.1m               h2bbff1b_0
pip                       21.2.4           py39haa95532_0
python                    3.9.7                h6244533_1
setuptools                58.0.4           py39haa95532_0
sqlite                    3.37.2               h2bbff1b_0
testing                   0.0.1                    pypi_0    pypi
tzdata                    2021e                hda174b7_0
vc                        14.2                 h21ff451_1
vs2015_runtime            14.27.29016          h5e58377_2
wheel                     0.37.1             pyhd3eb1b0_0
wincertstore              0.2              py39haa95532_2

To test it out I decided to open python and import the new package:

(github_test) C:\Users\MyName>python
Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import testing
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'testing'
>>>

Importing any of the other modules on the list by the name on the list does work. So I'm thinking my setup.py file is missing some information.

import setuptools

setuptools.setup(
    name='testing',
    version='0.0.1',
    url='https://github.com/accountname/reponame',
    author='My Name',
    author_email='REDACTED',
    description='testing123',
    install_requires=[]
)

I figure this would only work with a public repository. Ideally I would love to be able to use a private repository with this installation and distribution method. Any ideas?

Edits:

  • Removed my personal information
  • "Any ideas?" --> You can just point to a private repo and login using the prompt. Man what a time to be alive :D

CodePudding user response:

The setuptools.setup call in setup.py seems to be missing a packages parameter. So you are distributing an empty Python project without any importable package. You probably need either packages=setuptools.find_packages() or packages=['testing'].

  • Related