【问题标题】:Python3, gcc and clang on MacOSMacOS 上的 Python3、gcc 和 clang
【发布时间】:2020-03-12 09:41:56
【问题描述】:

我正在尝试在我的 Mac (MacOS 10.14.6 Mojave) 上制作 Python 脚本,但在安装模块(看门狗)时遇到了麻烦。我有内置的 Python 2,我用 Homebrew 安装了 Python 3。

如果终端python中的类型,我得到:

Python 2.7.16 (default, Oct 16 2019, 00:34:56) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

所以 Python 2 正确地使用了 GCC(Apple 提供的那个?我不确定)而不是 Clang。现在,如果我这样做 python -m pip install watchdog 它就可以了。但我想在 Python 3 上安装模块,由于某种原因使用 Clang 而不是 GCC。事实上,如果我输入 `python3',我会得到:

Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

我认为python3 -m pip install watchdog 会导致编译错误,因为 Python 3 没有使用 GCC。错误信息很长,可以在这里找到:https://pastebin.com/DEAKANQ9

在我的 $PATH 中,/usr/bin 之前有/usr/local/bin(安装了gcc),即

echo $PATH
/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin

我会说一切都设置正确,但显然情况并非如此。如何让 Python 3 使用 GCC 而不是 Clang?

【问题讨论】:

    标签: python python-3.x macos gcc clang


    【解决方案1】:

    我已经解决了这个问题。 首先,我删除了使用 pkg 安装程序安装的 Python 3.8(实际上是意外)。然后,我在 .bash_profile 中为 Python 3 创建了一个别名。另一个错误是我创建了文件 ~/.bashrc(就像在 Ubuntu 中一样)而不是编辑文件 ~/.bash_profile 来修改 $PATH。

    # ~/.bash_profile
    #
    # Python alias
    alias python=/usr/local/bin/python3
    # Setting PATH for Python 3.7.5 (Homebrew)
    PATH="/usr/local/bin:${PATH}"
    export PATH
    
    # Set module path
    PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages
    
    # Set PATH priority to Homebrew installation folder
    export PATH=/usr/local/bin:/usr/local/sbin:$PATH
    

    通过此设置,我能够安装模块并使其在我的脚本中运行!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-19
      • 2021-12-04
      • 1970-01-01
      • 2021-09-30
      • 1970-01-01
      • 2020-11-30
      • 2023-03-29
      • 1970-01-01
      相关资源
      最近更新 更多