You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从TestPyPI安装cli-assistant项目时遇版本匹配错误求助

Python项目TestPyPI安装失败问题排查

我正在学习Python项目打包与发布,遇到了一个问题:我的小型项目已经成功上传到TestPyPI,但执行安装命令时提示找不到匹配的版本。

安装命令与错误信息

执行的安装命令:

pip install -i https://test.pypi.org/simple/ cli-assistant

出现的错误:

Looking in indexes: https://test.pypi.org/simple/

ERROR: Could not find a version that satisfies the requirement cli-assistant (from versions: none)

ERROR: No matching distribution found for cli-assistant

项目的setup.py代码

from setuptools import setup, find_packages

with open("Description.rst", "r", encoding="utf-8") as fh:
    long_description = fh.read()
with open("requirements.txt", "r", encoding="utf-8") as fh:
    requirements = fh.read()

setup(
 name= 'cli-assistant',
 version= '0.0.5',
 author= 'my name',
 author_email= 'my email',
 license= 'MIT License',
 description='guide you with terminal and git commands',
 long_description=long_description,
 url='https://github.com/willsketch/Helper',
 py_modules=[ 'my_helper'],
 packages= find_packages(),
 install_requires = [requirements],
 classifiers=[
    'Programming Language :: Python',
    'Programming Language :: Python :: 3',
    'Programming Language :: Python :: 3.8',
    ],
 include_package_data=True,
 package_data={'helper':['examples.txt']},
 entry_points= {
     'console_scripts':[
         'helper = my_helper:cli',
     ]
 }
)

排查与解决办法

  • 分发包兼容性问题:检查TestPyPI项目页面的下载文件列表,确认存在适配你当前Python版本、操作系统的包。若只有源码包,需确保本地有编译依赖(如Windows的VC++构建工具、Linux的gcc),或重新上传兼容的wheel包。
  • install_requires格式错误:当前代码将requirements.txt全文作为单个依赖项传入,会导致打包异常。修改读取逻辑,拆分每行并过滤无效内容:
    with open("requirements.txt", "r", encoding="utf-8") as fh:
        requirements = [line.strip() for line in fh if line.strip() and not line.startswith("#")]
    
    重新打包上传后再尝试安装。
  • 项目结构与配置冲突:py_modules=['my_helper']和find_packages()同时使用可能引发冲突。如果my_helper.py是根目录单文件,删除packages=find_packages();如果属于helper包,调整py_modules路径或仅保留find_packages()。另外,package_data={'helper':['examples.txt']}要求存在helper包(含__init__.py),否则需删除该配置或补全包结构。
  • 缓存或索引问题:执行pip cache purge清除缓存后重新安装,同时确认命令中TestPyPI索引地址https://test.pypi.org/simple/格式正确(末尾需带/)。

内容的提问来源于stack exchange,提问作者lliw_wm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 06:05:22