0

This started from here, but has changed so much I felt I had to start another question.

I created a package (thompcoUtils) with python 3:

setup.py:

import setuptools

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

setuptools.setup(
    name="thompcoUtils",
    version="0.0.9",
    author="Jordan Thompson",
    author_email="Jordan@ThompCo.com",
    description="A collection of utilities",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/pypa/sampleproject",
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
)

built it:

python3 setup.py sdist bdist_wheel
running sdist
running egg_info
writing thompcoUtils.egg-info/PKG-INFO
writing dependency_links to thompcoUtils.egg-info/dependency_links.txt
writing top-level names to thompcoUtils.egg-info/top_level.txt
reading manifest file 'thompcoUtils.egg-info/SOURCES.txt'
writing manifest file 'thompcoUtils.egg-info/SOURCES.txt'
running check
creating thompcoUtils-0.0.9
creating thompcoUtils-0.0.9/thompcoUtils.egg-info
copying files to thompcoUtils-0.0.9...
copying README.md -> thompcoUtils-0.0.9
copying setup.py -> thompcoUtils-0.0.9
copying thompcoUtils.egg-info/PKG-INFO -> thompcoUtils-0.0.9/thompcoUtils.egg-info
copying thompcoUtils.egg-info/SOURCES.txt -> thompcoUtils-0.0.9/thompcoUtils.egg-info
copying thompcoUtils.egg-info/dependency_links.txt -> thompcoUtils-0.0.9/thompcoUtils.egg-info
copying thompcoUtils.egg-info/top_level.txt -> thompcoUtils-0.0.9/thompcoUtils.egg-info
Writing thompcoUtils-0.0.9/setup.cfg
Creating tar archive
removing 'thompcoUtils-0.0.9' (and everything under it)
running bdist_wheel
running build
installing to build/bdist.macosx-10.14-x86_64/wheel
running install
running install_egg_info
Copying thompcoUtils.egg-info to build/bdist.macosx-10.14-x86_64/wheel/thompcoUtils-0.0.9-py3.7.egg-info
running install_scripts
adding license file "LICENSE" (matched pattern "LICEN[CS]E*")
creating build/bdist.macosx-10.14-x86_64/wheel/thompcoUtils-0.0.9.dist-info/WHEEL
creating 'dist/thompcoUtils-0.0.9-py3-none-any.whl' and adding 'build/bdist.macosx-10.14-x86_64/wheel' to it
adding 'thompcoUtils-0.0.9.dist-info/LICENSE'
adding 'thompcoUtils-0.0.9.dist-info/METADATA'
adding 'thompcoUtils-0.0.9.dist-info/WHEEL'
adding 'thompcoUtils-0.0.9.dist-info/top_level.txt'
adding 'thompcoUtils-0.0.9.dist-info/RECORD'
removing build/bdist.macosx-10.14-x86_64/wheel

I added it to pypi like this:

twine upload --repository pypi  dist/*
Uploading distributions to https://test.pypi.org/legacy/
Uploading thompcoUtils-0.0.9-py3-none-any.whl
100%|██████████████████████████████████████| 6.21k/6.21k [00:00<00:00, 61.9kB/s]
Uploading thompcoUtils-0.0.9.tar.gz
100%|██████████████████████████████████████| 5.23k/5.23k [00:00<00:00, 8.69kB/s]

Using this .pypirc file:

[distutils]
index-servers=
    pypi
    testpypi

[pypi]
username: my_username
password: my_password

[testpypi]
repository: https://test.pypi.org/legacy/
username: my_other_username
password: my_other_password

I then installed it (from another folder) like this:

pip3 install --no-cache-dir  thompcoUtils -U
Collecting thompcoUtils
  Downloading https://files.pythonhosted.org/packages/00/da/d87bd82d95fbf90f5c4fb2083a3af514f14d46986ddebcc095bc6c8a4c48/thompcoUtils-0.0.9-py3-none-any.whl
Installing collected packages: thompcoUtils
Successfully installed thompcoUtils-0.0.9

and checked to make sure it was correctly installed:

pip3 list | grep thompcoUtils
thompcoUtils      0.0.9   

but when I tried to use it, it fails:

python3
Python 3.7.2 (default, Feb 12 2019, 08:15:36) 
Type "help", "copyright", "credits" or "license" for more information.
>>> import thompcoUtils
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'thompcoUtils'
jordanthompson
  • 888
  • 1
  • 12
  • 29

1 Answers1

0

OK, after many trials and tribulations to get everything just right, it turns out it isn't very hard.

created a folder with the following files and single sub-folder (thompcoutils - the name should be the name of your package):

./LICENSE
./install.sh
./thompcoutils
./thompcoutils/logging.py
./thompcoutils/os.py
./thompcoutils/__init__.py
./README.md
./setup.py

install.sh is a helper script to build and install the package into pypi.org:

#!/bin/bash
build=1
clean=1
if [[ $# -gt 0 ]]
then
  if [[ $1=="clean" ]]
  then
   build=0
  fi
fi

if [[ $clean -eq 1 ]]
then
  rm -rf dist
  rm -rf build
  rm -f *.whl
  rm -rf *.egg-info
fi

if [[ $build -eq 1 ]]
then
  python3 setup.py sdist bdist_wheel
  twine upload --repository pypi  dist/*
fi

The package name is thompcoutils as defined by the sub-folder name and the setup.py file.

Here is the setup.py:

import setuptools

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

setuptools.setup(
    name="thompcoutils",
    version="0.0.16",
    author="Jordan Thompson",
    author_email="Jordan@ThompCo.com",
    description="Another collection of utilities",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/pypa/sampleproject",
    packages=setuptools.find_packages(),
    install_requires=[
        'psutil', 'netifaces'
    ],
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
)

exclude_package_data = {'': ['install.sh']},

Note that you have to increment the version every time you push to the cloud. I hope this will help someone in the future (and serve as a reminder to me ;-)

jordanthompson
  • 888
  • 1
  • 12
  • 29