I am in the process of building my own Python module, just to get a hang of how it works. My Python is decent, but I have never build or submitted any packages before.
I followed a guide on Python Hosted as well as the official setuptools
documentation and this article on python.org. However, I still can't get this to work.
The package structure, with three modules (FileHelpers, TypeHelpers, XmlHelpers), looks like this:
PyLT3/
|- .git/
|- .idea/
|- setup.py
|- __init__.py
|- README.rst
|- LICENSE.txt
|- .gitignore
|- FileHelpers.py
|- TypeHelpers.py
|- XmlHelpers.py
Contents of setup.py
:
from setuptools import setup, find_packages
setup(
name='PyLT3',
version='0.1.3',
description='A collection of helper functions and NLP scripts',
long_description='During my time working on the PhD project PreDict, I have written and gathered a bunch of useful functions. They are collected here as part of the PyLT3 package.',
keywords='nlp xml file-handling helpers',
packages=find_packages(),
url='https://github.com/BramVanroy/PyLT3',
author='Bram Vanroy',
author_email='[email protected]',
license='MIT',
classifiers=[
'Development Status :: 1 - Planning',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering',
'Topic :: Text Processing',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.6',
],
project_urls = {
'Bug Reports': 'https://github.com/BramVanroy/PyLT3/issues',
'Source': 'https://github.com/BramVanroy/PyLT3',
},
python_requires='>=3.6',
)
Contents of MANIFEST.in:
prune .idea/*
With this data, I create a distribution:
python setup.py sdist
And a wheel:
python setup.py bdist_wheel
And the distribution is then uploaded to PyPi:
twine upload dist/*
To test this out, I download the package with pip:
pip install PyLT3
(Also used pip3
.) It successfully installs.
But when I then try a simple import PyLT3
, I get an error
import PyLT3
ModuleNotFoundError: No module named 'PyLT3'
This is odd, because pip told me the module was successfully installed. So I went looking for the module, and its *.info
is installed in C:\Python\Python36\Lib\site-packages\PyLT3-0.1.3.dist-info
. But I am assuming that this is not the actual package but just an info directory. There is no other package (e.g. PyLT3/
).
All of this leads me to believe that I did something wrong when packaging. What did I forget?
Your package doesn’t register a package named PyLT3
.
Your project stucture should look like this:
PyLT3/ # This is your project directory. Its name is irrelevant from the packaging point of view.
|- .git/
|- .idea/
|- setup.py
|- README.rst
|- LICENSE.txt
|- .gitignore
|- PyLT3/ # This is directory holds your python package.
|- __init__.py
|- FileHelpers.py
|- TypeHelpers.py
|- XmlHelpers.py
You can try this locally by running pip install -e .
from your project directory. This allows you to validate this works, before you publish.
A personal note: I would also strongly suggest using lower case package and module names, as per PEP8