在Python上上载新库

2024-10-01 05:03:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要在Python中部署一个库,并尝试使用pip来pip install它,但是在上传库之后,它只安装了一个信息文件:“oauth2clientz.egg info”

注意:我的库名是oauth2clientz:

我遵循的步骤如下:

  1. 创建一个名为oauth2clientz的文件夹

  2. 创建License.txt文件将我自己的许可证放入其中

  3. 在文件中创建Manifest.in并编写以下代码:

    global-include *.txt *.py
    
  4. 创建setup.py文件并编写以下代码:

    from setuptools import setup, find_packages
    
    setup(
    name='oauth2clientz',
    version='0.0.1',
    description='oauth2clientzskproject',
    long_description='outh2client',
    long_description_content_type='text/plain',
    url='https://github.com/sukan/oauth2clientz',
    author='sukan',
    author_email='sukanpp@gmail.com',
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Intended Audience :: Developers',
        'Topic :: Software Development :: Build Tools',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3.9',
    ],
    keywords='oauth2clientz project',
    )
    
  5. 在此文件夹中创建新文件夹,将其命名为oauth2clientz,并将所有我的库文件放入其中,包括(__init__.py

  6. 转到第一个OAuth2Client文件夹的cmd并输入:

    python setup.py sdist
    
  7. 它将生成这两个文件夹:“oauth2clientz.egg info”和“dist”

  8. 最后,输入cmd:

    twipe upload --repository-url https://upload.pypi.org/legacy/ dist/*
    
    enter username:
    
    enter password:
    

完成后,它被部署到Python org,但当我使用pip install oauth2clientz安装它时,它只安装了这个信息文件夹:“oauth2clientz.egg info”,它没有安装我添加到oauth2clientz文件夹中的库

为什么??我的工作哪里不对?我应该在setup.py文件中添加任何内容吗


Tags: installpip文件pyinfotxt文件夹信息
1条回答
网友
1楼 · 发布于 2024-10-01 05:03:34

正如@Klaus D所说的,您缺少packages

根据最近的最佳实践(src layoutpyproject.tomlsetup.cfg..),您的包通常应具有以下结构:

oauth2clientz/

  .. src/
     .. oauth2clientz/
        .. __ init__.py  # HERE you declare the version of your package
        .. module-1.py
        .. module-2.py

  .. tests/
     .. __ init__.py
     .. test_module_1.py
     .. test_module_2.py

  .. .editconfig
  .. .gitignore
  .. LISENCE
  .. MANIFEST.in
  .. README.md
  .. setup.cfg
  .. pyproject.toml

src/oauth2clientz/__;init.py

from module_1 import [..]
from module_2 import [..]


VERSION = (0, 0, 1, 'dev1')
__version__ = '.'.join(map(str, VERSION))


# YOU business logic 
# ..

# https://packaging.python.org/guides/using-manifest-in/
graft src/oauth2clientz
global-exclude __pycache__
global-exclude *.py[cod]

setup.cfg

# https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html
[metadata]
name = oauth2clientz
version = attr: oauth2clientz.__version__  # use 'attr:' helper get the version from the package 
description = oauth2 clientz project
long_description = file: README.md
long_description_content_type = text/markdown
author = sukan
author_email = sukanpp@gmail.com
# maintainer =
# maintainer_email =
license = BSD-3-Clause
license_file = LICENSE
# license_files = LICENSES/*
url = https://github.com/sukan/oauth2clientz
download_url = https://github.com/sukan/oauth2clientz
project_urls =
    Documentation = https://github.com/sukan/oauth2clientz#readme
    Issue Tracker = https://github.com/sukan/oauth2clientz/issues
    Source Code = https://github.com/sukan/oauth2clientz
keywords = oauth2 client
sclassifiers =
    Development Status :: 1 - Planning
    Intended Audience :: Developers
    License :: OSI Approved :: BSD License
    Operating System :: OS Independent
    Programming Language :: Python
    Programming Language :: Python :: 3
    Programming Language :: Python :: 3 :: Only
    Programming Language :: Python :: 3.6
    Programming Language :: Python :: 3.7
    Programming Language :: Python :: 3.8
    Programming Language :: Python :: 3.9
platforms = any

[options]
python_requires = >=3.6
packages = find:  # use 'find:' to finde packages located in 'package_dir' 
package_dir =
    = src
zip_safe = False

[options.packages.find]
where = src

[options.extras_require]
tests =
  pytest
  pytest-cov

code =
  flake8

pyproject.toml

[build-system]
# https://setuptools.readthedocs.io/en/latest/setuptools.html#setup-cfg-only-projects
requires = [
  "setuptools >= 58",
  "wheel"
]
build-backend = "setuptools.build_meta"

如果您在windows上,并且希望生成和发布包

pip install build wheel twine
py -m build -n  # don't forget '-n' flage to force using your project venv
py install -e .  # for editable mode 
py -m twine upload dist/*  # if everything is ok then pulish it on pypi

希望它能正常工作

相关问题 更多 >