上传至PyPI的包安装时提示“No matching distribution found”问题排查
自制PyPI包上传成功但无法安装的问题解决
问题现象
包上传至PyPI成功,但执行安装命令时出现如下错误:
ERROR: Could not find a version that satisfies the requirement Google-Ads-Transparency-Scraper==1.4 (from versions: none) ERROR: No matching distribution found for Google-Ads-Transparency-Scraper==1.4
项目目录结构
- GoogleAds
- GoogleAdsTransparency
- init.py
- main.py
- regions.py
- setup.py
- setup.cfg
- license.txt
- README.md
- GoogleAdsTransparency
相关配置文件内容
setup.py
"""Install packages as defined in this file into the Python environment.""" from setuptools import setup, find_packages setup( name="Google Ads Transparency Scraper", author="Farhan Ahmed", author_email="jattfarhan10@gmail.com", url="https://github.com/faniAhmed/GoogleAdsTransparencyScraper", description="A scraper for getting Ads from Google Transparency", version="1.4", packages=find_packages(), download_url= 'https://github.com/faniAhmed/GoogleAdsTransparencyScraper/archive/refs/tags/v1.2.tar.gz', keywords= ['Google', 'Transparency', 'Scraper', 'API', 'Google Ads', 'Ads', 'Google Transparency', 'Google Transparency Scraper', 'Google Ads Scrapre'], license='Securely Incorporation', install_requires=[ "setuptools>=45.0", "beautifulsoup4>=4.12.2", "Requests>=2.31.0", "lxml>=4.6.3", ], classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "License :: Free for non-commercial use", "Natural Language :: Urdu", "Operating System :: OS Independent", "Programming Language :: Python", ], platforms=["any"], )
setup.cfg
[metadata] description-file = README.md
init.py
from GoogleAdsTransparency.main import GoogleAds from GoogleAdsTransparency.main import show_regions_list
上传命令
python setup.py sdist twine upload dist/*
问题原因与解决步骤
核心问题
setup.py中的name参数使用了空格,PyPI会自动将空格转换为连字符(即Google-Ads-Transparency-Scraper),但本地打包生成的包元数据中名称仍为带空格的版本,导致pip查找时无法匹配对应版本。此外,download_url中的版本号与当前上传的1.4版本不匹配,也可能引发异常。
解决步骤
- 修正setup.py中的包名:将
name参数改为与PyPI页面一致的名称:name="Google-Ads-Transparency-Scraper", - 更新下载链接版本:将
download_url替换为对应v1.4版本的GitHub标签链接:download_url= 'https://github.com/faniAhmed/GoogleAdsTransparencyScraper/archive/refs/tags/v1.4.tar.gz', - 优化setup.cfg(可选但推荐):替换过时的
description-file配置,支持README.md的正确渲染:[metadata] long_description = file: README.md long_description_content_type = text/markdown - 重新打包并上传:
# 清理旧的dist文件(可选) rm -rf dist/ python setup.py sdist twine upload dist/* - 执行安装命令:等待PyPI缓存更新后,重新运行安装命令即可正常安装。
内容的提问来源于stack exchange,提问作者farhan jatt
相关产品推荐
相关产品推荐

