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

Bitbucket Pipeline Python部署突发失败求助:pipenv安装报错

问题描述

使用Bitbucket Pipeline部署Python项目,此前运行正常。本次仅修改一处错误文本后,部署突然失败,持续卡在pipenv install --skip-lock --system步骤。核心报错如下:
/usr/bin/python3: can't open file '/usr/local/lib/python3.7/dist-packages/pipenv/patched/pip': [Errno 2] No such file or directory
同时多个依赖包安装失败。

Pipeline配置
options:
  docker: true
image: python:3.8-slim


test: &test
  step:
    name: 'Build and Test'
    script:
      - echo "Your build and test goes here..."
lint: &lint
  step:
    name: 'Lint'
    script:
      - echo "Your linting goes here..."
      -


push-development: &push-development
  step:
    name: 'Deployment to Partners'
    deployment: partners
    image: google/cloud-sdk:latest
    caches:
      - docker
    trigger: 'manual'
    script:
      - echo ${KEY_FILE_AUTH} | base64 --decode --ignore-garbage > /tmp/gcloud-api.json
      - echo ${ENV_FILE} | base64 --decode --ignore-garbage > ./api/settings/.env
      - pip install pip pipenv --upgrade
      - pipenv install --skip-lock --system
      - pip install -r ./requirements.txt
      - source ./api/settings/.env
完整报错日志
42s
+ pipenv install --skip-lock --system
Installing dependencies from Pipfile...
An error occurred while installing protobuf==3.15.2! Will try again.
An error occurred while installing pyasn1==0.4.8! Will try again.
An error occurred while installing pyasn1-modules==0.2.8! Will try again.
An error occurred while installing pycparser==2.20! Will try again.
An error occurred while installing pydotplus==2.0.2! Will try again.
An error occurred while installing pyparsing==2.4.7! Will try again.
An error occurred while installing python-http-client==3.3.1! Will try again.
An error occurred while installing pytz==2021.1! Will try again.
An error occurred while installing requests==2.25.1! Will try again.
An error occurred while installing requests-file==1.5.1! Will try again.
An error occurred while installing requests-oauthlib==1.3.0! Will try again.
An error occurred while installing requests-toolbelt==0.9.1! Will try again.
An error occurred while installing rsa==4.7.2! Will try again.
An error occurred while installing scipy==1.6.1! Will try again.
An error occurred while installing sendgrid==6.5.0! Will try again.
An error occurred while installing sentry-sdk==0.16.5! Will try again.
An error occurred while installing singledispatch==3.6.0! Will try again.
An error occurred while installing six==1.15.0! Will try again.
An error occurred while installing sqlparse==0.4.1! Will try again.
An error occurred while installing starkbank-ecdsa==1.1.0! Will try again.
An error occurred while installing text-unidecode==1.3! Will try again.
An error occurred while installing uritemplate==3.0.1! Will try again.
An error occurred while installing urllib3==1.26.3! Will try again.
An error occurred while installing virtualenv==20.0.30! Will try again.
An error occurred while installing virtualenv-clone==0.5.4! Will try again.
An error occurred while installing zeep==4.0.0! Will try again.
An error occurred while installing django==3.1.6! Will try again.
An error occurred while installing pyjwt==1.7.1! Will try again.
An error occurred while installing pillow==7.2.0! Will try again.
An error occurred while installing rx==1.6.1! Will try again.
An error occurred while installing unidecode==1.1.1! Will try again.
An error occurred while installing django-rest-framework! Will try again.
An error occurred while installing requests-futures! Will try again.
An error occurred while installing django-constance! Will try again.
An error occurred while installing django-picklefield! Will try again.
An error occurred while installing django-environ! Will try again.
An error occurred while installing dj-database-url! Will try again.
Installing initially failed dependencies...
[pipenv.exceptions.InstallError]: /usr/bin/python3: can't open file '/usr/local/lib/python3.7/dist-packages/pipenv/patched/pip': [Errno 2] No such file or directory
ERROR: Couldn't install package: protobuf
 Package installation failed...
/usr/lib/python3.7/subprocess.py:858: ResourceWarning: subprocess 465 is still running
  ResourceWarning, source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=4 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=7 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/usr/lib/python3.7/subprocess.py:858: ResourceWarning: subprocess 466 is still running
  ResourceWarning, source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=6 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=9 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/usr/lib/python3.7/subprocess.py:858: ResourceWarning: subprocess 467 is still running
  ResourceWarning, source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=8 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=11 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/usr/lib/python3.7/subprocess.py:858: ResourceWarning: subprocess 468 is still running
  ResourceWarning, source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=10 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=13 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/usr/lib/python3.7/subprocess.py:858: ResourceWarning: subprocess 469 is still running
  ResourceWarning, source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=12 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=15 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/usr/lib/python3.7/subprocess.py:858: ResourceWarning: subprocess 470 is still running
  ResourceWarning, source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=14 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
sys:1: ResourceWarning: unclosed file <_io.FileIO name=17 mode='rb' closefd=True>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
解决方案

核心问题是Python版本不匹配:全局配置使用python:3.8-slim镜像,但部署步骤单独指定google/cloud-sdk:latest,该镜像自带Python 3.7。执行pip install pip pipenv --upgrade时,pipenv被安装到Python3.8路径,但部署步骤实际调用Python3.7,导致找不到对应文件。

方法一:统一Python版本

将部署步骤的镜像替换为和全局一致的Python 3.8镜像,若需要gcloud SDK则手动安装:

push-development: &push-development
  step:
    name: 'Deployment to Partners'
    deployment: partners
    image: python:3.8-slim
    caches:
      - pip
    trigger: 'manual'
    script:
      - apt-get update && apt-get install -y curl
      - curl https://sdk.cloud.google.com | bash
      - source $HOME/google-cloud-sdk/path.bash.inc
      - echo ${KEY_FILE_AUTH} | base64 --decode --ignore-garbage > /tmp/gcloud-api.json
      - echo ${ENV_FILE} | base64 --decode --ignore-garbage > ./api/settings/.env
      - pip install pip pipenv --upgrade
      - pipenv install --skip-lock --system
      - pip install -r ./requirements.txt
      - source ./api/settings/.env

方法二:在google-cloud-sdk镜像中指定Python版本安装

若必须使用google/cloud-sdk:latest,明确用Python3.7的pip安装并运行pipenv:

push-development: &push-development
  step:
    name: 'Deployment to Partners'
    deployment: partners
    image: google/cloud-sdk:latest
    caches:
      - pip
    trigger: 'manual'
    script:
      - echo ${KEY_FILE_AUTH} | base64 --decode --ignore-garbage > /tmp/gcloud-api.json
      - echo ${ENV_FILE} | base64 --decode --ignore-garbage > ./api/settings/.env
      - python3.7 -m pip install pip pipenv --upgrade
      - python3.7 -m pipenv install --skip-lock --system
      - pip install -r ./requirements.txt
      - source ./api/settings/.env

额外优化

  • 移除无用的docker缓存,改用pip缓存加速依赖安装
  • 确保Pipfile中的Python版本约束与使用的镜像版本一致

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 15:51:16