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

为何pip同时下载了我的PyPI包最新版与旧版本?

解决pip安装PyPI包时使用旧缓存版本的问题

问题描述

首次开发PyPI包tttk,上传v1.0.0后安装时提示setup.py错误,修改后上传v1.0.1,但安装时错误依旧。查看pip详细日志发现,pip始终使用缓存的v1.0.0版本包,报错FileNotFoundError: [Errno 2] No such file or directory: './README.md',相关日志如下:

Skipping link: not a file: https://pypi.org/simple/tkinter/
Given no hashes to check 0 links for project 'tkinter': discarding no candidates
  Created temporary directory: C:\Users\Len\AppData\Local\Temp\pip-unpack-sdbco3t1
  Looking up "https://files.pythonhosted.org/packages/78/e2/748aaa5d447f3ff3b0e997cbafd8b0f8cead796b059b92514c83d6411f07/tttk-1.0.0.tar.gz" in the cache
  Current age based on date: 4074
  Ignoring unknown cache-control directive: immutable
  Freshness lifetime from max-age: 365000000
  The response is "fresh", returning cached response
  365000000 > 4074
  Using cached tttk-1.0.0.tar.gz (16 kB)
  Added tttk from https://files.pythonhosted.org/packages/78/e2/748aaa5d447f3ff3b0e997cbafd8b0f8cead796b059b92514c83d6411f07/tttk-1.0.0.tar.gz to build tracker 'C:\\Users\\Len\\AppData\\Local\\Temp\\pip-build-tracker-6md7cbrk'
  Running setup.py (path:C:\Users\Len\AppData\Local\Temp\pip-install-7f41cz28\tttk_c1fc2afbed064900bbc613a248233cca\setup.py) egg_info for package tttk
  Created temporary directory: C:\Users\Len\AppData\Local\Temp\pip-pip-egg-info-3e78aanv
  Running command python setup.py egg_info
  Traceback (most recent call last):
    File "<string>", line 36, in <module>
    File "<pip-setuptools-caller>", line 34, in <module>
    File "C:\Users\Len\AppData\Local\Temp\pip-install-7f41cz28\tttk_c1fc2afbed064900bbc613a248233cca\setup.py", line 4, in <module>
      with open("./README.md", "r",encoding='utf-8') as fh:
  FileNotFoundError: [Errno 2] No such file or directory: './README.md'
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: 'D:\Python37\python.exe' -c '
  exec(compile('"'"''"'"''"'"''"'"'
  # This is <pip-setuptools-caller> -- a caller that pip uses to run setup.py

...

解决方案

1. 强制跳过缓存安装指定版本

直接执行以下命令,强制pip不使用本地缓存,拉取并安装v1.0.1版本:

pip install --no-cache-dir tttk==1.0.1

2. 确认PyPI上的v1.0.1包正确上传

  • 登录PyPI后台查看tttk项目的版本列表,确认v1.0.1已成功上传
  • 检查打包过程:确保README.md文件在打包根目录下,且setup.py中读取文件的路径使用绝对路径避免错误,可修改setup.py中的代码:
    import os
    from setuptools import setup
    
    readme_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "README.md")
    with open(readme_path, "r", encoding='utf-8') as fh:
        long_description = fh.read()
    
  • 重新打包时,执行python setup.py sdist后,检查生成的.tar.gz包内是否包含README.md文件

3. 手动清除pip缓存(可选)

如果上述方法无效,可手动删除pip的缓存目录:

  • Windows系统:删除C:\Users\Len\AppData\Local\pip\Cache目录
  • 执行删除后,再次运行pip install tttk==1.0.1即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 19:21:06