gpt4 book ai didi

python - Makefile 发现错误的 python 安装(python 2 而不是 python 3)

转载 作者:太空宇宙 更新时间:2023-11-03 21:43:30 26 4
gpt4 key购买 nike

我正在尝试在 Mac 上构建 Pyodide,但在我的默认 Python 安装中遇到了障碍。我已经尝试过解决方案 here ,但在使用 makefile 构建时仍然出现以下错误:

stg-MBP:pyodide stg$ make
make -C packages
../bin/pyodide buildall . ../build \
--ldflags="-O3 -s "BINARYEN_METHOD='native-wasm'" -Werror -s
EMULATED_FUNCTION_POINTERS=1 -s EMULATE_FUNCTION_POINTER_CASTS=1 -s
SIDE_MODULE=1 -s WASM=1 -s "BINARYEN_TRAP_MODE='clamp'" --memory-init-
file 0" --
host=/Users/stg/workspaces/pyodide/cpython/build/3.7.0/host
--target=/Users/stg/workspaces/pyodide/cpython/installs/python-3.7.0
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named pathlib
/usr/bin/python: No module named pyodide_build
make[1]: *** [all] Error 1

我的 .bash_profile 仅包含以下几行:

alias python=python3

# Setting PATH for Python 3.7
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH

但是,终端会返回对这些命令的以下响应

stg-MBP:pyodide stg$ which python
/usr/bin/python
stg-MBP:pyodide stg$ python --version
Python 3.7.0
stg-MBP:pyodide stg$ python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
stg-MBP:pyodide stg$ alias
alias python='python3'

我已经尝试清除哈希表并重新启动终端,但我仍然无法让 make 找到 python3 而不是 python2 (我假设罪魁祸首是 which python 仍然返回系统 python 而不是 python3。)是否有某种方法可以将 makefile 至少在当前终端 session 中指向正确的 python3 安装?

最佳答案

.bash_profile 仅由登录 shell 评估,并且别名不会由子 shell 继承,因此当 Pyodide 构建运行时别名不处于事件状态。

您需要在构建树中编辑 bin/pyoide,或者可以在名称 python 下放置一个指向 python3 的符号链接(symbolic link)并将该目录添加到 PATH 的前面,如下所示:

PATH="/path/to/directory-with-symbolic-link:$PATH" make

这样,python 将调用 Python 3 解释器,因为 PATH 是由子 shell 继承的。

关于python - Makefile 发现错误的 python 安装(python 2 而不是 python 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52675438/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com