gpt4 book ai didi

setuptools - 我构建了一个python包并上传到pypi。可以安装但不能导入 : ModuleNotFoundError

转载 作者:行者123 更新时间:2023-12-04 07:49:57 27 4
gpt4 key购买 nike

我构建了一个python包并上传到pypi .它安装得很好,但是在导入时我得到 ModuleNotFound错误。该错误在全新的 conda 环境中复制,在不同的机器上(Ubuntu、MacOS、Windows。虽然都在(新)conda 环境中)。我最后一次出现此错误是因为文件夹命名不正确,但这里并非如此。 GitHub repo在用于构建 whl 的分支和文件夹中。
有任何想法吗?
包是使用构建和安装的

python3 -m build
python3 -m twine upload dist/*
pip install pillaralgos
(pillar_env) jupyter-pomkos@jupyterubuntu:~$ python
Python 3.8.8 (default, Feb 24 2021, 21:46:12)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
---------------------------------------------------------------------------
>>> import pillaralgos
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pillaralgos'
>>>
它出现在 pip list
(pillar_env) jupyter-pomkos@jupyterubuntu:~$ pip list
Package Version
------------------ -------------------
# Truncated
pexpect 4.8.0
pickleshare 0.7.5
pillaralgos 1.0.1
Pillow 8.2.0
pip 21.0.1
sys.path确实包括安装库的目录。
(pillar_env) jupyter-pomkos@jupyterubuntu:~$ python
Python 3.8.8 (default, Feb 24 2021, 21:46:12)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/jupyter-pomkos/.conda/envs/pillar_env/lib/python38.zip', '/home/jupyter-pomkos/.conda/envs/pillar_env/lib/python3.8', '/home/jupyter-pomkos/.conda/envs/pillar_env/lib/python3.8/lib-dynload', '/home/jupyter-pomkos/.local/lib/python3.8/site-packages', '/home/jupyter-pomkos/.conda/envs/pillar_env/lib/python3.8/site-packages']
>>>
pip show说它安装在正确的环境和目录中。
(pillar_env) jupyter-pomkos@jupyterubuntu:~$ pip show pillaralgos
---------------------------------------------------------------------------
Name: pillaralgos
Version: 1.0.1
Summary: Algorithms for Pillar. Currently includes "mini" algorithms, nothing too sophisticated.
Home-page: https://github.com/pillargg/twitch_chat_analysis/tree/pypi_reorganize
Author: Peter Gates
Author-email: pgate89@gmail.com
License: UNKNOWN
Location: /home/jupyter-pomkos/.conda/envs/pillar_env/lib/python3.8/site-packages
Requires:
Required-by:
Note: you may need to restart the kernel to use updated packages.
ModuleNotFoundError出现在 jupyter 控制台、jupyterlab notebook 和终端 python 中。确认内核指向正确的 conda 目录(虽然我认为这个故障排除没有必要,因为错误是在不同的机器上复制的):
(pillar_env) jupyter-pomkos@jupyterubuntu:~$ nano ~/.local/share/jupyter/kernels/pillar_env/kernel.json
---------------------------------------------------------------------------
{
"argv": [
"/home/jupyter-pomkos/.conda/envs/pillar_env/bin/python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "Pillar Env",
"language": "python"
}

最佳答案

您当前的 setup.cfg 看起来像这样:

[options]
package_dir =
= pillaralgos
packages = find:
# ...

[options.packages.find]
where = pillaralgos
将此与您的项目目录结构进行比较,在我看来,您应该更改为以下内容:
[options]
packages = find:
# ...
如果我没记错的话, package_dir领域以及整个 [options.packages.find]部分是没有必要的。

关于setuptools - 我构建了一个python包并上传到pypi。可以安装但不能导入 : ModuleNotFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67035055/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com