macOS安装python glove库踩坑经验

MacOS 安装 python glove 库踩坑经验)

碰到的问题

课程需要使用 glove 库,手上的 windows 电脑这两天又送修了,只能在 mac 上安装 python 的相关环境。其他倒是都没有问题,在使用pip3 install glove-python的时候碰到如下问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(base) ➜  ~ pip3 install glove-python
Collecting glove-python
Using cached glove_python-0.1.0.tar.gz (263 kB)
Requirement already satisfied: numpy in ./anaconda3/lib/python3.8/site-packages (from glove-python) (1.20.1)
Requirement already satisfied: scipy in ./anaconda3/lib/python3.8/site-packages (from glove-python) (1.6.2)
Building wheels for collected packages: glove-python
Building wheel for glove-python (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /Users/admin/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-install-2fe6uukp/glove-python_8391e48580964dc2926dbe627d33d1a5/setup.py'"'"'; __file__='"'"'/private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-install-2fe6uukp/glove-python_8391e48580964dc2926dbe627d33d1a5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-wheel-h9nj2cq8
cwd: /private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-install-2fe6uukp/glove-python_8391e48580964dc2926dbe627d33d1a5/
Complete output (16 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.9-x86_64-3.8
creating build/lib.macosx-10.9-x86_64-3.8/glove
copying glove/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/glove
copying glove/glove.py -> build/lib.macosx-10.9-x86_64-3.8/glove
copying glove/corpus.py -> build/lib.macosx-10.9-x86_64-3.8/glove
running build_ext
building 'glove.glove_cython' extension
creating build/temp.macosx-10.9-x86_64-3.8
creating build/temp.macosx-10.9-x86_64-3.8/glove
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/admin/anaconda3/include -arch x86_64 -I/Users/admin/anaconda3/include -arch x86_64 -I/Users/admin/anaconda3/include/python3.8 -c glove/glove_cython.c -o build/temp.macosx-10.9-x86_64-3.8/glove/glove_cython.o -fopenmp -ffast-math -march=native
clang: error: unsupported option '-fopenmp'
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for glove-python
Running setup.py clean for glove-python
ERROR: Command errored out with exit status 1:
command: /Users/admin/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-install-2fe6uukp/glove-python_8391e48580964dc2926dbe627d33d1a5/setup.py'"'"'; __file__='"'"'/private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-install-2fe6uukp/glove-python_8391e48580964dc2926dbe627d33d1a5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' clean --all
cwd: /private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-install-2fe6uukp/glove-python_8391e48580964dc2926dbe627d33d1a5
Complete output (6 lines):
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help

error: option --all not recognized
----------------------------------------
ERROR: Failed cleaning build dir for glove-python
Failed to build glove-python
Installing collected packages: glove-python
Running setup.py install for glove-python ... error
ERROR: Command errored out with exit status 1:
command: /Users/admin/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-install-2fe6uukp/glove-python_8391e48580964dc2926dbe627d33d1a5/setup.py'"'"'; __file__='"'"'/private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-install-2fe6uukp/glove-python_8391e48580964dc2926dbe627d33d1a5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-record-xqhqx2mu/install-record.txt --single-version-externally-managed --compile --install-headers /Users/admin/anaconda3/include/python3.8/glove-python
cwd: /private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-install-2fe6uukp/glove-python_8391e48580964dc2926dbe627d33d1a5/
Complete output (8 lines):
running install
running build
running build_py
running build_ext
building 'glove.glove_cython' extension
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/admin/anaconda3/include -arch x86_64 -I/Users/admin/anaconda3/include -arch x86_64 -I/Users/admin/anaconda3/include/python3.8 -c glove/glove_cython.c -o build/temp.macosx-10.9-x86_64-3.8/glove/glove_cython.o -fopenmp -ffast-math -march=native
clang: error: unsupported option '-fopenmp'
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /Users/admin/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-install-2fe6uukp/glove-python_8391e48580964dc2926dbe627d33d1a5/setup.py'"'"'; __file__='"'"'/private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-install-2fe6uukp/glove-python_8391e48580964dc2926dbe627d33d1a5/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-record-xqhqx2mu/install-record.txt --single-version-externally-managed --compile --install-headers /Users/admin/anaconda3/include/python3.8/glove-python Check the logs for full command output.

主要报错就是command 'gcc' failed with exit status 1

踩坑 1 安装 gcc

因为报错是 gcc 的 error,发现电脑上并没有安装 gcc,于是brew install gcc安装得到 gcc 11.1.0
之后出现报错clang: error: unsupported option '-fopenmp',故再去安装 clang-omp,报错:

1
2
3
4
5
6
7
8
9
Error: No available formula with the name "clang-omp"
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching for similarly named formulae...
==> Searching local taps...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.

好家伙,原来 clang-omp 被迁移到了 llvm(这实在太麻烦了,违背作者的懒狗原则,故放弃)

踩坑 2 试图舍近求远使用 anaconda

看到 stackoverflow 上有朋友说 glove 只支持 3.5 以下的 python,低头一看自己是个 3.7,于是寻求包管理工具的帮助。
先是去brew install pyenv,可怜地发现已经不支持新版的 osx 了,只能卑微向 anaconda 低头。

以前使用过 anaconda 的管理工具,但是觉得体量过大,一直很抗拒安装。但事已至此,希望 conda 能救一条老命。
安装 anaconda bash 的教程网上很多,主要问题出在了镜像源……

1
UnavailableInvalidChannel: The channel is not accessible or is invalid.

好家伙一直以来用的清华镜像源似乎出现了问题,一搜发现
在这里插入图片描述
替换成中科大的镜像源

1
2
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/osx-64
conda config --add https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/osx-64

好嘛,再次试图 install glove

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
➜  ~ conda install python-glove
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

- python-glove

Current channels:

- https://mirrors.ustc.edu.cn/anaconda/pkgs/free/osx-64
- https://mirrors.ustc.edu.cn/anaconda/pkgs/free/noarch
- https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/osx-64
- https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/noarch
- https://repo.anaconda.com/pkgs/main/osx-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/osx-64
- https://repo.anaconda.com/pkgs/r/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

https://anaconda.org

and use the search bar at the top of the page.

查一查发现镜像源里根本没有 glove 这个库(也有可能是懒狗作者的操作不太正常)

换 github 源

继续在 csdn/stackoverflow 上寻找可能的解决方案,发现 glove 的安装在很多 windows 电脑上可能出现问题,但 macos 的解决方案基本没有……
参考了一位博主在 windows 上的解决方案(https://blog.csdn.net/weixin_45072810/article/details/109783520)
现在似乎是成功安装了

1
2
3
4
5
6
7
8
9
10
11
12
13
(base) ➜  ~ pip3 install https://github.com/JonathanRaiman/glove/archive/master.zip
Collecting https://github.com/JonathanRaiman/glove/archive/master.zip
Downloading https://github.com/JonathanRaiman/glove/archive/master.zip
\ 5.7 kB 8.9 MB/s
Requirement already satisfied: cython in ./anaconda3/lib/python3.8/site-packages (from glove==1.0.1) (0.29.23)
Requirement already satisfied: numpy in ./anaconda3/lib/python3.8/site-packages (from glove==1.0.1) (1.20.1)
Building wheels for collected packages: glove
Building wheel for glove (setup.py) ... done
Created wheel for glove: filename=glove-1.0.1-py3-none-any.whl size=4998 sha256=333928882f3857f80c341cdc50829d89e47fc7dcd58858ab03f5a68df490484d
Stored in directory: /private/var/folders/zb/bs3jp5756wx8bll4dj2bhg7w0000gp/T/pip-ephem-wheel-cache-nnihzarf/wheels/1c/f6/cf/371de84d071993d3402708a47a204d3022675d5761f8bf4b62
Successfully built glove
Installing collected packages: glove
Successfully installed glove-1.0.1

总结

踩坑过于严重……