5

I'm trying to publish my python package to private repository. I followed the official guide https://packaging.python.org/en/latest/tutorials/packaging-projects/ and everything seemed to be good. Here's terminal output:

(venv) C:\Users\xxx\PycharmProjects\my_package>twine upload --config-file .pypirc -r pypi dist/*
Uploading distributions to http://xxx/pypi/simple/
Enter your password:
Uploading my_package-0.1-py3-none-any.whl
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 8.03k/8.03k [00:01<00:00, 4.83kB/s]
Uploading my-package-0.1.tar.gz
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 7.40k/7.40k [00:00<00:00, 10.3kB/s]

But after publishing I can't see my package in repository neither by opening url in browser nor I can install it by pip.

I noticed that .whl comes with an underscore in name while .tar.gz comes with a dash. May it be be the issue? How can I find out what is wrong?

mara004
  • 1,435
  • 11
  • 24
StuffHappens
  • 6,457
  • 13
  • 70
  • 95
  • 2
    Just a note from my personal experience with PIP. It might take some time for Your package to appear publicly. In my case it was more than 24 hours. It's worth to try `--repository testpypi dist/*` as well. It's a test repo where it should appear much faster. – Domarm Jan 28 '22 at 09:17
  • 1
    Maybe your private repository isn't configured correctly? – D Malan Jan 28 '22 at 09:49
  • Could you try `http://xxx/pypi/` instead of `http://xxx/pypi/simple`. Also try `python3 -m twine upload --repository-url --username --password dist/*` – cyborg Feb 02 '22 at 09:29
  • To be able to help you, more information on your setup configuration would be needed. Could you post the content of your `setup.py`/`setup.cfg`? Which commands did you use to build the the sdist tarball and the wheel? – mara004 Feb 02 '22 at 13:36
  • You could also run `twine check dist/*` and `check-wheel-contents dist/*.whl` on your packages to see if any errors are reported. – mara004 Feb 02 '22 at 13:52
  • What is your private repository? Devpi, Nexus, Artifactory, something else? This is probably the most crucial piece of information needed to troubleshoot. – sinoroc Feb 03 '22 at 14:34

1 Answers1

2

Sure, it does not matter whether your package is uploaded to a private or a public repository. You can even not upload it to Git to publish it.

You can do that in 4 basic steps

  • Create a python package
  • Write setup.py
  • Build the package
  • Publish to PyPI via twine

Create a python package

In the following example, the demoverflow folder contains __init__.py, which is making demoverflow a python package.

└── demoverflow
    ├── demo.py
    └── __init__.py
# demo.py

class Demo:
    ...

import Demo at __init__.py to be able to import it from demoverflow (like: from demoverflow import Demo)

# __init__.py

from demo import Demo

Write setup.py

from setuptools import setup, find_packages

setup(
    name="demoverflow",
    version="0.0.1",
    author="Firstname Lastname",
    author_email="<demoverflow@support.com>",
    description="My demo package",
    packages=find_packages(),
    install_requires=[],
    keywords=['python'],
    classifiers=[
        "Development Status :: 1 - Planning",
        "Intended Audience :: Developers",
        "Programming Language :: Python :: 3",
        "Operating System :: Unix",
        "Operating System :: MacOS :: MacOS X",
        "Operating System :: Microsoft :: Windows",
    ]
)

NOTE: Before building the package, you should have the following file structure

├── demoverflow
│   ├── demo.py
│   └── __init__.py
└── setup.py

So setup.py and your package should be a neighbors

Build the package

If you already installed setuptools then can run the following command to generate a dist folder

python3 setup.py sdist bdist_wheel

Publish to PyPI

This command will require the username and password of your PyPI account

python3 -m twine upload dist/*
Artyom Vancyan
  • 5,029
  • 3
  • 12
  • 34
  • thanks for comprehensive instruction. But the answer does not contain response to the question: how to find out what is wrong. – StuffHappens Jan 28 '22 at 14:46
  • 2
    To answer exactly that question I need to see your project files, but you did not provide any. So I gave you a common answer. – Artyom Vancyan Jan 29 '22 at 07:30
  • You should consider updating your answer to use `python -m build --sdist --wheel` instead of the deprecated `python setup.py sdist bdist_wheel`. Ref: https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html – joanis Jul 08 '22 at 18:33