TestPyPI包安装报错:无法找到pandas版本,求排查pyproject.toml配置
问题描述
我正在尝试制作第一个Python包并上传至PyPI,已成功打包并上传到TestPyPI,但安装时出现如下错误:
ERROR: Could not find a version that satisfies the requirement pandas (from invian) (from versions: none) ERROR: No matching distribution found for pandas
我猜测问题出在pyproject.toml文件中,当前文件内容如下:
[build-system] requires = ["setuptools>=61.0.0", "wheel"] build-backend = "setuptools.build_meta" [project] name = "invian" version = "0.0.1" description="Package to analyze in vivo neural data" readme = "README.md" authors = [{ name = "my_name", email = "my_email"}] license = {file = "LICENSE"} classifiers = [ "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", 'Development Status :: 3 - Alpha', 'Intended Audience :: Science/Research', 'Programming Language :: Python :: 3' ] keywords = ["neuroscience", "electrophysiology", "research"] dependencies = [ 'pandas', 'numpy', 'scipy', 'matplotlib', 'seaborn' ] requires-python = ">= 3.6" [project.urls] Home = "https://github.com/someuser"
请问我的pyproject.toml文件格式是否存在问题?另外我未使用setup.py或setup.cfg。感谢解答!
问题分析与解决
你的pyproject.toml格式本身没有语法问题,安装报错的核心原因是TestPyPI是独立于正式PyPI的仓库,默认不会同步正式PyPI的包(比如pandas、numpy这类常用库)。当你从TestPyPI安装自己的包时,pip会仅在TestPyPI范围内查找所有依赖,自然找不到只在正式PyPI存在的pandas等包。
解决步骤:
- 安装时通过
--extra-index-url参数同时指定正式PyPI作为依赖源:
该命令会让pip优先从TestPyPI拉取你的pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ invianinvian包,而依赖的pandas、numpy等库则从正式PyPI获取。
额外优化建议:
- 调整
requires-python版本:pandas最新版本已不再支持Python3.6,建议将requires-python = ">= 3.6"改为>=3.8(可根据你实际使用的依赖版本灵活调整),避免后续出现版本兼容问题。 - 统一字符串引号格式:类ifiers列表中同时使用了双引号和单引号,虽然不影响功能,但统一为一种引号格式能让配置文件更整洁。
内容的提问来源于stack exchange,提问作者Alex Legaria
相关产品推荐
相关产品推荐

