GNU make:检查是否需要安装python模块

2024-10-01 17:33:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在Ubuntu bionic上使用GNU make,我需要检查是否需要安装带有apt-get的Ubuntu python包

我在我的Makefile中尝试了这一点,以捕获python导入错误(ModuleNotFoundError):

MY_PYTHON     := $(shell echo `which python3`)
MY_SETUPTOOLS := $(shell $(MY_PYTHON) -c 'import setuptools' )

ifneq ($(findstring /python3,$(MY_PYTHON)),/python3)
$(info 1. Installing python)
TMP := $(shell apt-get -y install python python3)
MY_PYTHON := $(shell echo `which python3`)
endif

ifeq ($(findstring ModuleNotFoundError,$(MY_SETUPTOOLS)),ModuleNotFoundError)
$(info 1. Installing setuptools)
TMP := $(shell apt-get -y install python-setuptools python3-setuptools)
endif

.PHONY: test
test:
        cd $(THIS_DIR); cd tests; py.test -s test_mytools.py
        make clean

当我运行sudo make test时,我看到下面的错误被打印到终端上;但它不会触发使用apt-get安装python3-setuptools的逻辑:

$ sudo make test
make[2]: Entering directory '/home/mpennington/foo'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'setuptools'

如何修复此问题,以便make安装python3-setuptools


Tags: testechowhichgetmakeubuntumy错误

热门问题