pip 安装成功后出现 ModuleNotFoundError

发布于 2025-01-16 19:49:03 字数 1318 浏览 3 评论 0原文

我刚刚创建的包有问题,我想将其上传到 PyPi。包的结构如下:

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

setup.py指定包的名称为“alexandria-python”。我希望我可以将其称为“alexandria”,但该名称已在 PyPi 上保留。 当我第一次使用“pip install -e .”在本地安装软件包时,它工作正常。我可以从 Anaconda 打开 Spyder 或 Jupyter,使用“import alexandria”,不会返回错误。 我还可以毫无问题地导入和使用任何子包。

所以我然后继续在 test-Pypi 上上传包。效果很好,该包可以在以下位置找到: https://test.pypi.org/project/alexandria-python/

我尝试使用 pip install -i https://test.pypi.org/simple/ 将其安装在我的计算机上亚历山大蟒蛇 安装似乎有效(“成功安装 alexandria-python-0.0.1”),但是当我打开 Spyder/Jupyter 并尝试“导入 alexandria”时,出现错误:

Traceback(最近一次调用最后):

文件“/tmp” /ipykernel_24757/3637483902.py”,第 1 行,在 import alexandria

ModuleNotFoundError: No module named 'alexandria'

这更奇怪,因为该包是在 conda 环境中找到的。例如,使用命令“conda list”会产生:

/home/romain/installs/anaconda3 环境中的软件包:

名称版本构建通道 _ipyw_jlab_nb_ext_conf 0.1.0 py39h06a4308_0
_libgcc_mutex 0.1 主要
_openmp_mutex 4.5 1_gnu
雪花石膏 0.7.12 pyhd3eb1b0_0
alexandria-python 0.0.1 pypi_0 pypi

这样就找到了包。

最后,我不明白错误的根源是什么:包结构问题、python 路径问题...有人知道吗?多谢。

I have a problem with a package that I just created and that I want to upload on PyPi. The structure of the package is as follows:

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

the setup.py specifies the name of the package to be "alexandria-python". I wish I can call it "alexandria", but the name is already reserved on PyPi.
When I first install the package locally, with "pip install -e .", it works fine. I can open Spyder or Jupyter from Anaconda, use "import alexandria", no error is returned.
I can also import and use any of the sub-packages without problems.

So I then moved on uploading the package on test-Pypi. It worked fine, the package can be found at:
https://test.pypi.org/project/alexandria-python/

I try to install it on my computer, using pip install -i https://test.pypi.org/simple/ alexandria-python
The install seems to work ("Successfully installed alexandria-python-0.0.1"), but when I open Spyder/Jupyter and try "import alexandria", I get an error:

Traceback (most recent call last):

File "/tmp/ipykernel_24757/3637483902.py", line 1, in
import alexandria

ModuleNotFoundError: No module named 'alexandria'

This is all the more strange since the package is found in the conda environment. Using the command "conda list" for instance yields:

packages in environment at /home/romain/installs/anaconda3:

Name Version Build Channel
_ipyw_jlab_nb_ext_conf 0.1.0 py39h06a4308_0
_libgcc_mutex 0.1 main
_openmp_mutex 4.5 1_gnu
alabaster 0.7.12 pyhd3eb1b0_0
alexandria-python 0.0.1 pypi_0 pypi

So the package is found.

In the end, I don't understand what can be the source of the error: problem of package structure, python path... Has anyone an idea? Thanks a lot.

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

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

发布评论

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

评论(1

碍人泪离人颜 2025-01-23 19:49:03

您尚未将实际的包代码上传到 PyPi。

如果您转到此处到您的 PyPi 下载页面,然后下载源发行版,您将看到它包含您的 .egg-info 文件,但不包含您的代码。

在上传到 PyPi 之前,请确保您的存档文件包含所需的所有内容。

You haven't uploaded your actual package code to PyPi.

If you go here to your PyPi downloads page and then download the source distribution, you will see that it contains your .egg-info file but not you code.

Make sure your archive file has everything it needs before uploading to PyPi.

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