在 Windows 或 POSIX 上的 Makefile 中获取基本 Python 解释器

问题描述 投票:0回答:1

我正在尝试制作一个具有系统Python路径的

Makefile
,它可以在Windows和POSIX系统上运行。

这适用于 macOS 和 Windows WSL,但如果您激活了虚拟环境,它会返回 venv 的路径(不是系统 Python 的路径):

SYSTEM_PYTHON = $(shell which python3)

无论 venv 是否激活,这都有效,但在 Windows 上不起作用:

SYSTEM_PYTHON = $(shell python3 -c "import sys; print(sys.base_prefix)")/bin/python

如何制作一个既适用于 Windows 又适用于 POSIX 的

SYSTEM_PYTHON
环境变量,无论之前是否激活了虚拟环境?

python windows macos makefile gnu-make
1个回答
0
投票

即使我有 venv,这也适用于我的 Windows

ifeq ($(OS),Windows_NT)
    SYSTEM_PYTHON = $(shell python -c "import sys; print(sys.base_prefix)")\\python.exe
else
    SYSTEM_PYTHON = $(shell python3 -c "import sys; print(sys.base_prefix)")/bin/python3
endif

all:
    @echo "System Python is located at: $(SYSTEM_PYTHON)"
© www.soinside.com 2019 - 2024. All rights reserved.