setup.py sdist 创建一个没有包的存档

发布于 2025-01-17 05:17:57 字数 1613 浏览 3 评论 0原文

我有一个名为 Alexandria 的项目,我想将其作为包上传到 PyPi 上。为此,我有一个名为 alexandria-python 的顶级文件夹,其中放置了包以及使用 setup.py 创建包存档所需的所有元素。文件夹 alexandria-python 具有以下结构:

|- setup.py
|- README.md
|- alexandria (root folder for the package)
  |- __init__.py
  |- many sub-packages

然后,按照许多教程创建可上传的存档,我打开一个终端,cd 到 alexandria-python,并使用命令:

python setup.py sdist

这会创建其他文件夹,因此 alexandria-python 的结构是现在:

|- setup.py
|- README.md
|- alexandria (root folder for the package)
  |- __init__.py
  |- many sub-packages
|- alexandria.egg-info
|- dist

一切看起来都很好,根据我的理解,该包现在应该存档在 dist 文件夹中。但是,当我打开 dist 文件夹并提取已创建的 alexandria-0.0.2.tar.gz 存档时,它不包含“alexandria”包。因此,除了最重要的元素:包,其他所有东西似乎都在那里,如图所示:

< img src="https://i.sstatic.net/FhMdp.png" alt="在此处输入图像描述">

接下来,当我将项目上传到 test-PyPi 然后 pip 安装它时,任何尝试导入模块从工具箱中获取会导致 ModuleNotFoundError。我的包怎么没有上传到存档?我是不是在做一些非常愚蠢的事情?

注意:如果它有帮助,这是我的 setup.py 文件的结构:

from setuptools import setup

# set up the package
setup(
    name = "alexandria",
    license = "Other/Proprietary License",
    version = "0.0.2",
    author = "Romain Legrand",
    author_email = "[email protected]",
    description = "a software for Bayesian time-series econometrics applications",
    python_requires = ">=3.6",
    keywords=["python", "Bayesian", "time-series", "econometrics"])

I have a project called Alexandria that I want to upload on PyPi as a package. To do so, I have a top folder called alexandria-python in which I put the package and all the elements required to create a package archive with setup.py. The folder alexandria-python has the following structure:

|- setup.py
|- README.md
|- alexandria (root folder for the package)
  |- __init__.py
  |- many sub-packages

Then, following many tutorials to create an uploadable archive, I open a terminal, cd to alexandria-python, and use the command:

python setup.py sdist

This creates additional folders, so the structure of alexandria-python is now:

|- setup.py
|- README.md
|- alexandria (root folder for the package)
  |- __init__.py
  |- many sub-packages
|- alexandria.egg-info
|- dist

everything looks fine, and from my understanding the package should now be archived in the dist folder. But when I open the dist folder and extract the alexandria-0.0.2.tar.gz archive that has been created, it does not contain the 'alexandria' package. Everything else thus seems to be there, except the most important element: the package, as shown on the image:

enter image description here

Following, when I upload the project to test-PyPi and then pip install it, any attempt to import a module from the toolbox results in a ModuleNotFoundError. How is it that my package does not get uploaded to the archive? Am I doing something very silly?

Note: in case it can help, this is the structure of my setup.py file:

from setuptools import setup

# set up the package
setup(
    name = "alexandria",
    license = "Other/Proprietary License",
    version = "0.0.2",
    author = "Romain Legrand",
    author_email = "[email protected]",
    description = "a software for Bayesian time-series econometrics applications",
    python_requires = ">=3.6",
    keywords=["python", "Bayesian", "time-series", "econometrics"])

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东京女 2025-01-24 05:17:57

您的 setup.py 既没有 py_modules 也没有 。必须有其中之一。在你的情况下,alexandria是一个包,所以

setup(
…
    packages = ['alexandria'],
…
)

或者

from setuptools import find_packages, setup

......

    packages = find_packages('.')

Your setup.py has neither py_modules nor packages. Must have one of those. In your case alexandria is a package so

setup(
…
    packages = ['alexandria'],
…
)

or

from setuptools import find_packages, setup

    packages = find_packages('.')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文