我正在构建自己的Python模块,只是为了了解它是如何工作的。我的Python很不错,但我以前从未构建或提交过任何包。
我遵循了关于Python托管和文档的指南,以及关于python.org的这篇文章。不过,我还是不能让这件事起作用。
包结构由三个模块(FileHelpers、TypeHelpers、XmlHelpers)组成,如下所示:
PyLT3/
|- .git/
|- .idea/
|- setup.py
|- __init__.py
|- README.rst
|- LICENSE.txt
|- .gitignore
|- FileHelpers.py
|- TypeHelpers.py
|- XmlHelpers.pysetup.py含量
from setuptools import setup, find_packages
setup(
name='PyLT3',
version='0.1.3',
description='A collection of helper functions and NLP scripts',
long_description='During my time working on the PhD project PreDict, I have written and gathered a bunch of useful functions. They are collected here as part of the PyLT3 package.',
keywords='nlp xml file-handling helpers',
packages=find_packages(),
url='https://github.com/BramVanroy/PyLT3',
author='Bram Vanroy',
author_email='bramvanroy@hotmail.com',
license='MIT',
classifiers=[
'Development Status :: 1 - Planning',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering',
'Topic :: Text Processing',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.6',
],
project_urls = {
'Bug Reports': 'https://github.com/BramVanroy/PyLT3/issues',
'Source': 'https://github.com/BramVanroy/PyLT3',
},
python_requires='>=3.6',
)MANIFEST.in的内容:
prune .idea/*使用这些数据,我创建了一个发行版:
python setup.py sdist还有一个轮子:
python setup.py bdist_wheel然后将发行版上传到PyPi:
twine upload dist/*为了测试这一点,我用pip下载了包裹:
pip install PyLT3(还使用了pip3.)它成功地安装。
但是当我尝试一个简单的import PyLT3时,我会得到一个错误
导入PyLT3 ModuleNotFoundError:没有名为“PyLT3”的模块
这很奇怪,因为pip告诉我模块安装成功了。所以我去找这个模块,它的*.info安装在C:\Python\Python36\Lib\site-packages\PyLT3-0.1.3.dist-info中。但我假设这不是实际的包,而是一个信息目录。没有其他包(例如PyLT3/)。
所有这些让我相信我在包装时做错了什么。我忘了什么?
发布于 2018-02-28 15:01:08
您的包没有注册名为PyLT3的包。
您的项目结构应该如下所示:
PyLT3/ # This is your project directory. Its name is irrelevant from the packaging point of view.
|- .git/
|- .idea/
|- setup.py
|- README.rst
|- LICENSE.txt
|- .gitignore
|- PyLT3/ # This is directory holds your python package.
|- __init__.py
|- FileHelpers.py
|- TypeHelpers.py
|- XmlHelpers.py您可以通过在项目目录中运行pip install -e .在本地尝试此操作。这允许您在发布之前验证此工作。
个人提示:我还强烈建议使用小写包和模块名,如PEP8所示
https://stackoverflow.com/questions/49031878
复制相似问题