【问题标题】:use apt-get install python packages in .gitlab-ci.yml在 .gitlab-ci.yml 中使用 apt-get install python 包
【发布时间】:2017-01-06 11:36:38
【问题描述】:

我的gitlab-ci.yml 我安装了 python-pandas,但我不能从 python 中使用它。

$ cat .gitlab-ci.yml
image: python:2

test:
  script:
  - apt-get update -qy
  - apt-get install -y python-pip python-pandas
  - ls /usr/local/lib/python2.7/site-packages
  - python -c 'import pandas'

运行器失败并显示此消息::

 $ python -c 'import pandas'
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  ImportError: No module named pandas
  ERROR: Build failed: exit code 1

我尽量不安装 pip 作为要求的熊猫(旧的熊猫库就足够了) 并且很想了解为什么没有暴露python包?这看起来像一个隐含的 virtualenv !?

【问题讨论】:

  • 您是否尝试使用 ie 安装带有 pip 的旧版本。 pandas==0.17
  • 顺便说一句:使用 python -V 检查您使用的是 Python 2 还是 3。
  • 主要原因是在调试阶段加快构建速度,这就是我想继续使用 apt-get 安装的方式
  • 我建议您基于python:2 创建自己的 Docker 映像并安装所有额外的软件包。这样您就可以在 CI 中使用之前对其进行测试,从而加快测试速度并避免任何意外。
  • 如果是私有注册表,它将是image: gitlab.corp.com:5000/your-python-image:latest

标签: python pandas gitlab-ci gitlab-ci-runner


【解决方案1】:

你应该在before_script中创建一个virtualvenv:

before_script:
  - apt-get -qq update && apt-get -qq install -y python
  - apt-get -qq update
  - apt-get -qq install -y python python-virtualenv python-pip
  - virtualenv venv
  - . venv/bin/activate
  - python -V
  - pip install pandas

【讨论】:

    猜你喜欢
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    • 2020-12-22
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    相关资源
    最近更新 更多