#1474 已经安装uv配置了环境变量可是运行的时候依然报错是怎么回事

52.68* Posted at: 2 hours ago 👁20

已经安装uv配置了环境变量可是运行uv run app.py的时候依然报以下错是怎么回事
× No solution found when resolving script dependencies:
╰─▶ Because ffmpeg-python was not found in the package registry and you require ffmpeg-python>=0.2.0, we can conclude that your requirements are

  unsatisfiable.

  hint: An index URL (https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple) returned a 403 Forbidden error. This could indicate lack of valid
  authentication credentials, or the package may not exist on this index.

17 Replies

这个错误表明 uv 在尝试安装 ffmpeg-python 依赖时,从您配置的清华镜像源(https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple)收到了 403 Forbidden 错误,导致无法找到并安装该包。

核心原因与解决方案:

  1. 镜像源问题:清华镜像源可能暂时无法访问或需要特定配置。最简单的解决方法是切换回官方 PyPI 源
  2. 依赖包名称ffmpeg-python 这个包在某些环境下可能存在安装问题。pyVideoTrans 实际主要依赖的是 ffmpeg 命令行工具本身,而非这个特定的 Python 包装库。

请按以下步骤操作:

步骤一:清除 uv 的缓存和当前环境
在命令行中执行以下命令,清除可能导致冲突的缓存和锁文件:

uv cache clean

步骤二:尝试使用官方 PyPI 源安装
不使用任何镜像源,让 uv 直接从官方源获取包:

uv run --no-cache app.py

或者,更彻底地,删除可能存在的 pyproject.tomluv.lock 文件(如果存在),然后重新运行。

步骤三(如果上述步骤无效):检查系统 FFmpeg
pyVideoTrans 的核心是调用 ffmpeg 命令行工具。请确保您的系统已正确安装 FFmpeg 并将其添加到环境变量 PATH 中。

  • 在命令行中输入 ffmpeg -version,如果能看到版本信息,说明 FFmpeg 已正确安装。
  • 如果未安装,请访问 FFmpeg 官网 下载并安装,或者通过包管理器安装(如 Windows 上用 choco install ffmpeg,macOS 上用 brew install ffmpeg)。

完成以上步骤后,再次尝试运行 uv run app.py

如果问题依旧,请提供您完整的 pyproject.toml 文件内容,以便进行更深入的分析。

如何将镜像源修改为官方的

要强制 uv 使用官方 PyPI 源,请按以下步骤操作:

方法一:清除镜像配置并重新运行

  1. 首先清理 uv 的缓存:

    uv cache clean
  2. 检查您的项目目录或系统环境变量中是否设置了镜像源。删除或注释掉以下文件中的相关配置(如果存在):

    • pyproject.toml 中的 [tool.uv.sources][tool.uv.index] 部分
    • 环境变量 UV_INDEX_URLUV_EXTRA_INDEX_URL
    • 全局 uv 配置文件(通常位于 ~/.config/uv/uv.toml
  3. 重新运行命令:

    uv run app.py

方法二:使用 --index-url 参数显式指定官方源

uv run --index-url https://pypi.org/simple app.py

方法三:设置临时环境变量
在命令行中临时设置环境变量,指向官方源:

  • Windows (CMD/PowerShell):

    set UV_INDEX_URL=https://pypi.org/simple
    uv run app.py
  • macOS/Linux:

    UV_INDEX_URL=https://pypi.org/simple uv run app.py

推荐首先尝试方法一,它最直接。如果问题依旧,请提供您项目目录下 pyproject.toml 文件的内容,以便进一步诊断。

上面的方法都不行啊

如果上述方法都无法解决问题,请按以下步骤进行深度排查:

步骤一:检查项目依赖配置
请提供您的 pyproject.toml 文件内容,特别是 [project][tool.uv] 部分,确认依赖声明是否正确。

步骤二:手动安装核心依赖
暂时绕过 uv,使用 pip 手动安装核心依赖来测试网络连通性:

pip install --index-url https://pypi.org/simple ffmpeg-python

步骤三:检查 uv 版本和配置

  1. 运行 uv --version 确认 uv 版本
  2. 检查全局 uv 配置:

    # 查看全局配置
    uv config list
    # 或直接查看配置文件
    cat ~/.config/uv/uv.toml  # Linux/macOS

步骤四:临时禁用所有镜像源
在项目目录下创建一个干净的临时环境:

# 进入项目目录
cd /path/to/your/project

# 清理所有配置
uv cache clean

# 使用 --isolated 参数运行,忽略所有配置文件
uv run --isolated app.py

步骤五:检查网络限制
如果仍然报 403 错误,可能是:

  • 公司网络或防火墙限制
  • DNS 解析问题

请尝试:

# 测试网络连通性
curl -I https://pypi.org/simple/ffmpeg-python/

如果以上步骤都无法解决,请提供:

  1. 完整的 pyproject.toml 文件内容
  2. 运行 uv --version 的输出
  3. 完整的错误日志

这样可以帮助进一步诊断问题根源。

uv版本:uv 0.9.8 (85c5d3228 2025-11-07), pyproject.toml 文件内容:[project]
name = "wx"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [

"ffmpeg-python>=0.2.0",
"flask>=3.1.2",
"openai>=2.7.2",
"pydub>=0.25.1",
"waitress>=3.0.2",
"whisperx>=3.7.4",

]

[[tool.uv.index]]
url = "https://pypi.org/simple app.py"

问题出在您的 pyproject.toml 文件配置错误。[[tool.uv.index]] 部分的 URL 格式不正确,它包含了 app.py 这个文件名。

请按以下步骤修正:

  1. 编辑 pyproject.toml 文件,将:

    [[tool.uv.index]]
    url = "https://pypi.org/simple app.py"

    修改为:

    [[tool.uv.index]]
    url = "https://pypi.org/simple"

    或者,更简单的方法是直接删除整个 [[tool.uv.index]] 部分,因为 https://pypi.org/simple 本身就是 uv 的默认源。

  2. 清理缓存并重新运行

    uv cache clean
    uv run app.py

这个错误的配置导致 uv 在解析索引源时遇到了格式异常的网络地址,从而触发了依赖解析失败。

依然有如下错误: uv run app.py
× No solution found when resolving script dependencies:
╰─▶ Because ffmpeg-python was not found in the package registry and you require

  ffmpeg-python>=0.2.0, we can conclude that your requirements are unsatisfiable.

  hint: An index URL (https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple) returned a 403
  Forbidden error. This could indicate lack of valid authentication credentials, or the package     
  may not exist on this index.

问题依然存在,uv 仍然在尝试使用清华镜像源。这表明有更深层的配置在起作用。请按以下步骤彻底解决:步骤一:完全清除 uv 配置和缓存删除所有可能的 uv 配置文件:# 删除全局配置
rm -rf ~/.config/uv # Linux/macOS

或 Windows: del %USERPROFILE%.config\uv

清理缓存

uv cache clean --all-force步骤二:创建临时测试目录创建一个全新的目录来测试:mkdir test_project
cd test_project步骤三:创建最小化的 pyproject.toml在 test_project 目录中创建只包含以下内容的 pyproject.toml:[project]
name = "test"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [

"ffmpeg-python>=0.2.0"

]步骤四:测试安装cd test_project
uv run python -c "import ffmpeg; print('Success!')"如果这个测试成功,说明问题出在您原项目的环境配置上。步骤五:检查环境变量运行以下命令检查是否有设置镜像源的环境变量:env | grep -i pypi # Linux/macOS

或 Windows: set | findstr /i pypi检查是否有:PYPI_INDEX_URLPIP_INDEX_URLUV_INDEX_URL等环境变量。如果找到,请取消设置或将其值改为 https://pypi.org/simple。如果以上步骤仍然无效,请尝试使用 pip 直接安装来验证网络连通性:pip install --index-url https://pypi.org/simple ffmpeg-python

继续,是不是在这个app.py脚本中写死了?# /// script

requires-python = "==3.12.*"

dependencies = [

"ffmpeg-python>=0.2.0",

"flask>=3.1.2",

"openai>=2.7.2",

"pydub>=0.25.1",

"waitress>=3.0.2",

"whisperx>=3.7.4",

]

[[tool.uv.index]]

url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"

[[tool.uv.index]]

name = "pytorch-cu128"

url = "https://download.pytorch.org/whl/cu128"

explicit = true

[[tool.uv.index]]

name = "pytorch-cpu"

url = "https://download.pytorch.org/whl/cpu"

explicit = true

[tool.uv.sources]

torch = [

{ index = "pytorch-cu128", marker = "sys_platform == 'win32' or sys_platform == 'linux'" },

{ index = "pytorch-cpu", marker = "sys_platform == 'darwin'" }, # darwin 为 macOS

]

torchaudio = [

{ index = "pytorch-cu128", marker = "sys_platform == 'win32' or sys_platform == 'linux'" },

{ index = "pytorch-cpu", marker = "sys_platform == 'darwin'" },

]

///

impo
......
x.html')

@app.route('/v1/audio/transcriptions', methods=['POST'])
def audio_transcriptions():

if 'file' not in request.files:
    return jsonify({"error": "请求中未包含文件部分"}), 400
file = request.files['file']
if file.filename == '':
    return jsonify({"error": "未选择任何文件"}), 400

model_id = request.form.get('model', DEFAULT_MODEL)
model_name = 'large-v3' if model_id == 'large-v3-turbo' else model_id
if model_name not in ALLOWED_MODELS:
    model_name = DEFAULT_MODEL

language = request.form.get('language') or None
prompt = request.form.get('prompt')

logging.info(f"收到请求: 模型='{model_id}', 语言='{language or '自动检测'}', 提示词='{'有' if prompt else '无'}'")

input_file_path = None
processed_wav_path = None
try:
    suffix = os.path.splitext(file.filename)[1]
    with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
        file.save(tmp.name)
        input_file_path = tmp.name

    logging.info(f"正在将上传的文件 '{file.filename}' 转换为标准的 16kHz 单声道 WAV 格式...")
    with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_wav:
        processed_wav_path = tmp_wav.name
    
    try:
        (
            ffmpeg
            .input(input_file_path)
            .output(processed_wav_path, ac=1, ar=16000, acodec='pcm_s16le', vn=None)
            .run(capture_stdout=True, capture_stderr=True, overwrite_output=True)
        )
        logging.info("文件格式转换成功。")
    except ffmpeg.Error as e:
        error_details = e.stderr.decode('utf-8', errors='ignore')
        logging.error(f"FFmpeg 文件转换失败: {error_details}")
        return jsonify({"error": f"音频/视频文件处理失败,可能是文件已损坏或格式不受支持。"}), 400

    audio = whisperx.load_audio(processed_wav_path)
    model = get_whisper_model(model_name)
    
    # ---
    # *** FIX IS HERE ***
    # ---
    transcribe_options = {}
    if language:
        transcribe_options['language'] = language
    if prompt:
        # 使用正确的参数名 'prompt'
        transcribe_options['prompt'] = prompt
        
    result = model.transcribe(audio, batch_size=BATCH_SIZE, **transcribe_options)
    
    model_a, metadata = whisperx.load_align_model(language_code=result["language"], device=DEVICE)
    result = whisperx.align(result["segments"], model_a, metadata, audio, DEVICE, return_char_alignments=False)
    
    diar_model = get_diarize_model()
    if diar_model:
        try:
            diarize_segments = diar_model(audio)
            result = whisperx.assign_word_speakers(diarize_segments, result)
        except Exception as e:
            logging.error(f"说话人分离运行时失败: {e}。将回退到单说话人模式。")
    
    speakers = {segment.get('speaker') for segment in result["segments"] if 'speaker' in segment}
    is_single_speaker = len(speakers) 

是的!问题找到了。在您的 app.py 文件开头,确实写死了清华镜像源配置:

[[tool.uv.index]]
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"

这行配置强制 uv 使用清华镜像源,而该镜像源返回 403 错误。请按以下步骤修复:

步骤一:修改 app.py 文件
将文件开头的配置部分修改为:

# /// script
requires-python = "==3.12.*"
dependencies = [
    "ffmpeg-python>=0.2.0",
    "flask>=3.1.2", 
    "openai>=2.7.2",
    "pydub>=0.25.1",
    "waitress>=3.0.2",
    "whisperx>=3.7.4",
]

[[tool.uv.index]]
name = "pytorch-cu128"
url = "https://download.pytorch.org/whl/cu128"
explicit = true

[[tool.uv.index]]
name = "pytorch-cpu" 
url = "https://download.pytorch.org/whl/cpu"
explicit = true

[tool.uv.sources]
torch = [{ index = "pytorch-cu128", marker = "sys_platform == 'win32' or sys_platform == 'linux'" },
        { index = "pytorch-cpu", marker = "sys_platform == 'darwin'" }]
torchaudio = [{ index = "pytorch-cu128", marker = "sys_platform == 'win32' or sys_platform == 'linux'" },
             { index = "pytorch-cpu", marker = "sys_platform == 'darwin'" }]
///

关键修改:删除了这行:

[[tool.uv.index]]
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"

步骤二:清理缓存并重新运行

uv cache clean
uv run app.py

这样配置后,uv 将使用默认的官方 PyPI 源来安装除 PyTorch 之外的所有包,应该能解决 403 错误问题。

继续,这不都注释了么?对脚本还能有影响?

您说得对!我犯了个错误。# /// script/// 之间的内容不是注释,而是 uv 的脚本依赖声明。这是 uv 的一个特殊语法,用于在单个 Python 文件中声明依赖。

这些配置确实会生效,并且优先级很高。问题就出在:

[[tool.uv.index]]
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"

这行配置强制 uv 使用清华镜像源,即使您在其他地方配置了官方源也会被这个覆盖。

解决方案:

直接在 app.py 文件中删除这行配置:

# /// script
requires-python = "==3.12.*"
dependencies = [
    "ffmpeg-python>=0.2.0",
    "flask>=3.1.2", 
    "openai>=2.7.2",
    "pydub>=0.25.1",
    "waitress>=3.0.2",
    "whisperx>=3.7.4",
]

# 删除这一行 ▼▼▼
# [[tool.uv.index]]
# url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"

[[tool.uv.index]]
name = "pytorch-cu128"
url = "https://download.pytorch.org/whl/cu128"
explicit = true

[[tool.uv.index]]
name = "pytorch-cpu" 
url = "https://download.pytorch.org/whl/cpu"
explicit = true
///

然后清理缓存重新运行:

uv cache clean
uv run app.py

这样 uv 就会回退到使用默认的官方 PyPI 源来安装 ffmpeg-python 等包了。

删除了,可以运行uv run app.py 的时候 还会有下面的错误
error: An opening tag (# /// script) was found without a closing tag (# ///). Ensure that every line between the opening and closing tags (including empty lines) starts with a leading #.

这个错误说明 uv 脚本依赖声明的格式有问题。# /// script# /// 之间的每一行都必须以 # 开头,包括空行。

请将 app.py 文件开头的部分修改为:

# /// script
# requires-python = "==3.12.*"
# dependencies = [
#     "ffmpeg-python>=0.2.0",
#     "flask>=3.1.2", 
#     "openai>=2.7.2",
#     "pydub>=0.25.1",
#     "waitress>=3.0.2",
#     "whisperx>=3.7.4",
# ]
# 
# [[tool.uv.index]]
# name = "pytorch-cu128"
# url = "https://download.pytorch.org/whl/cu128"
# explicit = true
# 
# [[tool.uv.index]]
# name = "pytorch-cpu" 
# url = "https://download.pytorch.org/whl/cpu"
# explicit = true
# 
# [tool.uv.sources]
# torch = [{ index = "pytorch-cu128", marker = "sys_platform == 'win32' or sys_platform == 'linux'" },
#         { index = "pytorch-cpu", marker = "sys_platform == 'darwin'" }]
# torchaudio = [{ index = "pytorch-cu128", marker = "sys_platform == 'win32' or sys_platform == 'linux'" },
#              { index = "pytorch-cpu", marker = "sys_platform == 'darwin'" }]
# ///

关键修改:

  1. 每一行都以 # 开头
  2. 空行也要有 #
  3. 确保有正确的结束标记 # ///

或者更简单的方法:直接删除整个 uv 脚本依赖声明部分,只保留普通的 Python 代码,然后在项目根目录使用 pyproject.toml 来管理依赖。

清理缓存后重新运行:

uv cache clean
uv run app.py

好的已经运行正常了,作者这种写死源的做法真是浪费时间,鄙视他一下!

很高兴问题解决了!确实,在代码中硬编码特定镜像源确实会给用户带来不必要的麻烦,特别是当镜像源不可用时。

现在您的应用应该可以正常运行了。如果后续遇到其他依赖安装问题,记得 uv 脚本依赖声明要求所有行(包括空行)都必须以 # 开头。

祝您使用顺利!

Post Your Reply
Open source and free maintenance is not easy. If this project is helpful to you, please consider making a small donation to help the project continue to maintain and update.

Donate: https://ko-fi.com/jianchang512

Trending Questions