3

I have been unsuccessful in creating a Python package distribution. I have followed the instructions in https://packaging.python.org/tutorials/packaging-projects/ and this is what happens. For e.g. if I create the necessary files and folders as required

first/ first/ __init__.py setup.py LICENSE README.md myfirst.py 

I have made the package name as 'first' in setup.py

import setuptools with open("README.md", "r") as fh: long_description = fh.read() setuptools.setup( name="tvg11", version="0.0.1", author="Ganesh", author_email="[email protected]", description="A small example package", 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", ], ) 

Then I run the commands

python setup.py sdist bdist_wheel python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/* 

which creates dist/, build/ and first.egg-info.

Now I find that if I am in the same directory and do a

pip install --index-url https://test.pypi.org/simple/ first 

Then I find that this creates a new folder pycache with the compiled code and I am able to do import first

first/ first/ __pycache__ # new! build/ dist/ first.egg.info __init__.py setup.py LICENSE README.md myfirst.py 

However, if I am in any other folder other the root folder 'first/first' and I do a

pip install --index-url https://test.pypi.org/simple/ first 

I get a 'Successfully installed' but when I invoke python and do an import first I get ModuleNotFoundError "No module 'first'".

Please let me know what I am doing wrong. The instructions were so simple.

2
  • 1
    Please show your full setup script. Looks like the first package is not bundled. Also, run pip show -f first and verify all files are listed. Commented Oct 22, 2018 at 10:35
  • @hoefling 'pip show -f first'gives nothng. Since I had done a 'pip install tiwne' earler, when I checked 'pip -f show twine' I get a list of all files - .py,.pyc, LICENSE etc. Yes it looks like I am missing some step in 'bundling' the package Commented Oct 22, 2018 at 11:51

1 Answer 1

3

You should have looked interactively in test.pypi.org ...

You would have immediately noticed that your own project in not known as first but as tvg11. What matters is the name and version number inside the setup.py file and not the folder name.

But the real cause is that you have put the files of the package at same level as the setup.py file and used packages=setuptools.find_packages(). So as you have no packages below setup.py, find_packages found nothing, and you have built and interesting package containing little more than setup.py and README.md.

How to fix:

First you should build a more common structure for your package:

 - first - setup.py - LICENSE - README.md - first - __init__.py - myfirst.py 

That way find_package will find the content of the first subfolder as the source for the tvg11 package.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!! That worked! Strange the example given in packaging.python.org/tutorials/packaging-projects was not clear at all. Appreciate it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.