“python makefile无法找到python命令”

huangapple go评论61阅读模式
英文:

python makefile can't find python command

问题

On my M2 Mac, Python makefile does not work. I'm running everything in iterm2.

Error when running makefile:

➜ make test-local
/bin/sh: python: command not found
make: *** [test-local] Error 127

Python path:

➜ which -a python
python: aliased to /usr/local/bin/python3.9

➜ python
Python 3.9.17 (main, Jun 20 2023, 17:20:08)
[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits", or "license" for more information.

My .zshrc file. I read other SOF articles so I tried adding to my path to no avail.

alias python=python3

PYTHON="$PATH:/Users/lewis.chi/Library/Python/3.9/bin"
PYTHON1="/usr/local/bin/python3.9"
PYTHON11="/usr/local/bin/"

export PATH=$PATH:$PYTHON:$PYTHON1:$PYTHON11
英文:

On my M2 Mac, Python makefile does not work. I'm running everything in iterm2.

test-local:
        TREE_SITTER_LIB_PATH=./test python -m pytest

Error when running makefile:

➜ make test-local
/bin/sh: python: command not found
make: *** [test-local] Error 127

Python path:

➜ which -a python
python: aliased to /usr/local/bin/python3.9

➜ python
Python 3.9.17 (main, Jun 20 2023, 17:20:08)
[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

My .zshrc file. I read other SOF articles so I tried adding to my path to no avail.

alias python=python3

PYTHON="$PATH:/Users/lewis.chi/Library/Python/3.9/bin"
PYTHON1="/usr/local/bin/python3.9"
PYTHON11="/usr/local/bin/"

export PATH=$PATH:$PYTHON:$PYTHON1:$PYTHON11

答案1

得分: 1

这是你的问题:

➜ which -a python
python: 别名为 /usr/local/bin/python3.9

这意味着 python 是一个 shell alias。Shell 别名只对你正在使用的 shell 本地,不会导出到子 shell,并且 make 对别名一无所知。因此,你不能在 make 配方中运行别名。

如果你想让这个工作,你必须找到另一种方法。你可以使用一个 make 变量并在命令行上设置它为正确的值,你可以使用一个 python 脚本代替别名,你可以将 python 设置为对 python3 的符号链接,等等。

但你不能使用 shell 别名。

顺便说一下,对于 shell 函数也是一样:它们也只对当前 shell 本地,不会导出到外部。

英文:

This is your problem:

➜ which -a python
python: aliased to /usr/local/bin/python3.9

This implies that python is a shell alias. Shell aliases are local to the shell that you're using, they are not exported to sub-shells and make doesn't know anything about aliases. So, you cannot run aliases from within make recipes.

If you want to make this work, you have to find a different way. You can use a make variable and set it to the right value on the command line, you can use a python script instead of an alias, you can make python a symbolic link to python3, etc. etc.

But you cannot use a shell alias.

Ditto for shell functions, by the way: they are also local to the shell and not exported.

huangapple
  • 本文由 发表于 2023年6月29日 15:18:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76578823.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定