создал пакет, но не может использовать его из pypi - PullRequest
0 голосов
/ 10 марта 2019

Это началось с здесь , но изменилось настолько сильно, что я почувствовал, что должен был начать другой вопрос.

Я создал пакет (thompcoUtils) с 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",
    ],
)

построил:

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

Я добавил его в pypi так:

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]

Использование этого файла .pypirc:

[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

Затем я установил его (из другой папки) так:

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

и проверил, правильно ли он установлен:

pip3 list | grep thompcoUtils
thompcoUtils      0.0.9   

но когда я попытался его использовать, он не работает:

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'

1 Ответ

0 голосов
/ 10 марта 2019

ОК, после многих испытаний и невзгод, чтобы все было правильно, оказалось, что это не очень сложно.

создал папку со следующими файлами и одной подпапкой (thompcoutils - имя должноимя вашего пакета):

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

install.sh - вспомогательный скрипт для сборки и установки пакета в 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

Имя пакета thompcoutils в соответствии с именем подпапки и файлом setup.py.

Вот файл 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']},

Обратите внимание, чтовам нужно увеличивать версию каждый раз, когда вы отправляете в облако.Я надеюсь, что это поможет кому-то в будущем (и послужит мне напоминанием; -)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...