python - 未找到自定义 python 包
问题描述
我从 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',
)
__init__.py
:
name='tomaszslittlehelpers'
项目树:
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
pip install tomaszslittlehelpers
安装到
C:\users ... \python37\Lib\site-packages\tomaszslittlehelpers-0.0.1.dist-info
没有tomaszslittlehelpers
文件夹
解决方案
你的包装有问题。您的代码不会添加到您的发行版中。您正在使用packages=setuptools.find_packages(),
,但似乎没有任何要寻找的包。看起来您的代码位于__init__.py
项目根目录的文件中。这很可能是行不通的。
两种解决方案:
重命名
__init__.py
为tomaszslittlehelpers.py
并替换packages=setuptools.find_packages(),
为py_modules=['tomaszslittlehelpers'],
.将您的移动
__init__.py
到一个tomaszslittlehelpers
子目录,并且find_packages()
应该能够找到它。
在这两种情况下,您都应该能够像这样导入您的代码:import tomaszslittlehelpers
.
推荐阅读
- javascript - 如何在 WebGrid 中查找单个复选框的选中状态
- css - 如何为不同的图像尺寸自动隐藏图像底部的固定尺寸
- android - 为什么我的 Flutter 应用在退出时会下拉到屏幕底部?
- python-3.x - 错误:只有整数、切片 (`:`)、省略号 (`...`)、numpy.newaxis (`None`) 和整数或布尔数组是有效索引
- azure - Azure 活动目录是否容易受到 DoS 或 DDOS 攻击
- javascript - 覆盖 Vue 的 mixin 方法
- django - 如何在单个 django 视图中组合两个 ModelForm
- ssl - 有没有办法在 Active Directory 中强制实施 SSL 或 TLS?
- r - R *** 捕获 segfault *** 地址 0x6,导致“内存未映射”
- php - PHP问题:无法通过关联数组打印行号白色循环