- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在构建自己的 Python 模块,只是为了了解它的工作原理。我的 Python 很不错,但我以前从未构建或提交过任何包。
我遵循了 Python Hosted 上的指南以及the official setuptools
documentation和这篇关于 python.org 的文章.但是,我仍然无法让它工作。
包含三个模块(FileHelpers、TypeHelpers、XmlHelpers)的包结构如下所示:
PyLT3/
|- .git/
|- .idea/
|- setup.py
|- __init__.py
|- README.rst
|- LICENSE.txt
|- .gitignore
|- FileHelpers.py
|- TypeHelpers.py
|- XmlHelpers.py
setup.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 ,我下载了 the package用 pip :
pip install PyLT3
(也使用了pip3
。)安装成功。
但是当我尝试一个简单的 import PyLT3
时,我得到一个错误
import PyLT3
ModuleNotFoundError: No module named 'PyLT3'
这很奇怪,因为 pip 告诉我模块已成功安装。所以我去寻找模块,它的 *.info
安装在 C:\Python\Python36\Lib\site-packages\PyLT3-0.1.3.dist-info
。但我假设这不是实际的包,而只是一个信息目录。没有其他包(例如 PyLT3/
)。
所有这些让我相信我在打包时做错了什么。我忘记了什么?
最佳答案
您的包没有注册名为 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
关于python - 用pip下载自己的模块, "No module named ...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49031878/
我是一名优秀的程序员,十分优秀!