MacOS上的Python3,gcc和clang

我正在尝试在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","credits" or "license" for more information.

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

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

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?

liuzengmis 回答:MacOS上的Python3,gcc和clang

我已解决此问题。 首先,我删除了使用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

使用此设置,我能够安装模块并使其在脚本中正常工作!

本文链接:https://www.f2er.com/3090345.html

大家都在问