创建了包,但是不能从pypi使用它 [英] created package but cannot use it from pypi

查看:83
本文介绍了创建了包,但是不能从pypi使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这从此处开始,但是具有变化很大,我觉得我不得不再提一个问题.

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

我用python 3创建了一个包(thompcoUtils)

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",
    ],
)

建造了它:

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:

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]

使用此.pypirc文件:

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'

推荐答案

好吧,经过多次尝试和磨难,使一切都变得正确,事实证明这并不困难.

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

创建了一个包含以下文件和单个子文件夹的文件夹(thompcoutils-名称应为程序包的名称):

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是一个帮助程序脚本,用于将该软件包生成并安装到 pypi.org 中:

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

软件包名称为 thompcoutils ,由子文件夹名称和setup.py文件定义.

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

这是setup.py:

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 ;-)

这篇关于创建了包,但是不能从pypi使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆