python-3.x - Bitbucket:ModuleNotFoundError:没有名为“numpy”的模块
问题描述
我正在尝试使用以下方法在 Bitbucket 中设置单元测试bitbucket-pipelines.yml
image: python:3.7.3
pipelines:
default:
- step:
caches:
- pip
script: # Modify the commands below to build your repository.
- pip3 install --upgrade pip setuptools wheel
- pip3 install -r requirements.txt
- step:
script:
- python3 -m unittest discover -vp 'Test*.py'
文件 requirements.txt 如下:
tensorflow==2.4.1
Keras==2.4.3
pandas==1.1.3
requests==2.24.0
matplotlib==3.3.2
numpy==1.19.2
numpy 存在于需求中,但是当它运行单元测试时,我收到以下错误:
import numpy as np
ModuleNotFoundError: No module named 'numpy'
解决方案
问题是,在第一步中,您使用 pip3 安装依赖项,因为它是不同的容器,所以在下一步中将不可用。如果要保留依赖项,则必须按如下方式缓存它们:
image: python:buster
definitions:
caches:
pip3: /usr/local/lib/python3.9/site-packages
路径是可变的,具体取决于您拥有的 python 版本,您可以pip3 show <dependency>
在管道中运行命令以验证是否是正确的路径。
并且您需要将缓存添加到需要依赖项的步骤中,在您的情况下是第二步:
image: python:3.7.3
definitions:
caches:
pip3: <path>
pipelines:
default:
- step:
name: First step
caches:
- pip3
script: # Modify the commands below to build your repository.
- pip3 install --upgrade pip setuptools wheel
- pip3 install -r requirements.txt
- step:
name: Second step
caches:
- pip3
script:
- python3 -m unittest discover -vp 'Test*.py'
推荐阅读
- python-3.x - Sorting a stacked bar chart as a whole along Y-axis, based on the value of a particular category field using Altair
- java - Android Google Play games signin error 12501
- mapbox - Adding circle polygon to Map on click
- react-native - Handel screen from reactivelist to details screen
- java - Where are the definitions of the operators in Java language?
- c - 在C语言中检查数字是否为整数
- swift - SDL 音频回调的 Swift 实现中的噪声和失真
- javascript - 在 laravel 中编写变量 javascript
- cmake - 是否有 FindHDF4.cmake 包可以找到 cmake 未安装的 HDF4 库?
- elm - Elm:如何在后续请求中使用来自一个 HTTP 请求的数据