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

如何配置tox-docker在容器内而非本地安装依赖?

Solution

To resolve the local installation failure of cuda-python on your M2 Pro MacBook while running tests via tox-docker, modify your tox.ini with the following changes:

Modified tox.ini Sections

[testenv:test-docker-env]
docker =
    py-3.11
skip_install = true  # Skip local installation of project and dependencies
deps =
    -r{toxinidir}/requirements/requirements.txt  # Now safe to include—installs only in container
    -r{toxinidir}/requirements/requirements-test.txt
commands =
    python -m pytest --cov=src \
        --cov-report term-missing \
        --cov-report xml:coverage-reports/coverage-BUILD_{env:BUILD_NUMBER:0}.xml \
        --junitxml=xunit-reports/xunit-result-BUILD_{env:BUILD_NUMBER:0}.xml \
        -vv \
        tests/
# Map local report directories to container to preserve test results
docker_volumes =
    {toxinidir}/coverage-reports:/app/coverage-reports
    {toxinidir}/xunit-reports:/app/xunit-reports

[docker:py-3.11]
# Use a CUDA-enabled image with Python 3.11 (supports ARM64 for M2)
image = nvidia/cuda:12.2.0-python3.11-runtime-ubuntu22.04
working_dir = /app  # Align with tox's project copy path
# Ensure CUDA runtime libraries are accessible
docker_run_env =
    LD_LIBRARY_PATH=/usr/local/nvidia/lib64:/usr/local/cuda/lib64
# Grant container access to host GPU (required for CUDA execution; omit if tests don't need GPU)
docker_run_args = --gpus all

Key Changes Explained

  • skip_install = true: This stops tox from trying to install your project or dependencies on your local MacBook. All setup and test execution happens entirely inside the Docker container.
  • Re-enabled requirements.txt: Since local installation is skipped, including this file no longer causes failures—cuda-python is installed only in the container where CUDA libraries are present.
  • CUDA-enabled Docker Image: The base python:3.11 image lacks CUDA runtime libraries, which are mandatory for cuda-python. Using an official NVIDIA CUDA image with Python pre-installed ensures all necessary dependencies are available.
  • Volume Mapping: The docker_volumes directive ensures test reports (coverage, xunit) generated inside the container are saved back to your local machine.
  • GPU Access: The --gpus all argument lets the container access your host's GPU (if needed for test execution). If your tests don't require actual GPU usage, you can omit this line—cuda-python will still install successfully as long as the CUDA runtime is present in the image.

Prerequisites

  • Ensure you have Docker Desktop installed on your M2 MacBook with ARM64 support enabled.
  • Install the tox-docker plugin if you haven't already:
    pip install tox-docker
    
  • For GPU access, set up the NVIDIA Container Toolkit (relevant if you're using an external NVIDIA GPU with your MacBook, or if your tests require GPU execution).

内容的提问来源于stack exchange,提问作者MaxU - stand with Ukraine

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 22:28:13