找不到自定义python包

Tom*_*asz 0 python pip pypi

我遵循了python.org的本教程, 并成功上传到PyPI并使用pip进行安装,但我所得到的只是

ModuleNotFoundError: No module named 'tomaszslittlehelpers'

有什么建议么?

从上方文件夹中的文件导入时,导入在本地进行。

套件名称为 tomaszslittlehelpers

setup.py

import setuptools

with open('README.md', 'r') as fh:
    long_description = fh.read()

setuptools.setup(
        name='tomaszslittlehelpers',
        version='0.0.2',
        author='TomaszAndrzej',
        author_email='',
        description='Tomasz\'s Little Helpers',
        long_description=long_description,
        long_description_content_type='text/markdown',
        url='',
        packages=setuptools.find_packages(),
        classifiers=[
                'Programming Language :: Python :: 3',
                'License :: OSI Approved :: MIT License',
                'Operating System :: OS Independent',
                ],
        python_requires='>=3.7',

        )
Run Code Online (Sandbox Code Playgroud)

__init__.py

name='tomaszslittlehelpers'
Run Code Online (Sandbox Code Playgroud)

项目树:

tomaszslittlehelpers
    build
        bdist.win-amd64
    dist
        tomaszslittlehelpers-0.0.2-py3-none-any.whl
        tomaszslittlehelpers-0.0.2.tar.gz
    tomaszslittlehelpers.egg-info
        dependency_links.txt
        PKG-INFO
        SOURCES.txt
        top_level.txt
    __init__.py
    LICENSE
    README.md
    setup.py
Run Code Online (Sandbox Code Playgroud)

pip install tomaszslittlehelpers
安装到

C:\users ... \python37\Lib\site-packages\tomaszslittlehelpers-0.0.1.dist-info 没有tomaszslittlehelpers文件夹

sin*_*roc 7

您的包装有问题。您的代码未添加到您的发行版。您正在使用,packages=setuptools.find_packages(),但似乎没有要寻找的任何包装。看起来您的代码在__init__.py项目根目录的文件中。这很可能行不通。

两种解决方案:

  • 重命名__init__.pytomaszslittlehelpers.py并替换packages=setuptools.find_packages(),py_modules=['tomaszslittlehelpers'],

  • 将您移动__init__.py到一个tomaszslittlehelpers子目录,并且find_packages()应该能够找到它。

在这两种情况下,您都应该能够像这样导入代码:import tomaszslittlehelpers