在MacOS上安装Python3、gcc和clang

3

我正在尝试在我的Mac上(MacOS 10.14.6 Mojave)编写Python脚本,并遇到安装模块(watchdog)的问题。我有内置的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.

我认为,由于Python 3没有使用GCC,因此python3 -m pip install watchdog会导致编译错误。错误消息非常长,可以在此处找到: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?
1个回答

3

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

有了这个设置,我能够安装这个模块并在我的脚本中成功使用它!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接