파이썬3 노트

pipenv로 libmf나 implicit을 install할 때 cmath관련 에러가 난다면

Jonchann 2021. 1. 12. 17:48

에러

먼저, 이게 어떤 에러인가 하면 libmf나 implicit에서 사용하는 C언어를 컴파일 할 때 나는 에러인데 사실은 path가 꼬여서 발생한 것이다.
다른 블로그 글을 읽어보니 cmath와 math.c 패스가 들어간 곳이 달라 어딜 읽어야 하는지 몰라 그런것이라고 했다.

                            ^
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    198 warnings and 20 errors generated.
    error: command 'clang' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/jungwon.choi/.local/share/virtualenvs/newspicks-feed-engine-fcIudhtP/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9w/55qsb5b107x791frt6_ymd3h0000gp/T/pip-install-vp4v0djd/implicit/setup.py'"'"'; __file__='"'"'/private/var/folders/9w/55qsb5b107x791frt6_ymd3h0000gp/T/pip-install-vp4v0djd/implicit/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/9w/55qsb5b107x791frt6_ymd3h0000gp/T/pip-record-hb_7zcjf/install-record.txt --single-version-externally-managed --compile --install-headers /Users/jungwon.choi/.local/share/virtualenvs/newspicks-feed-engine-fcIudhtP/include/site/python3.8/implicit Check the logs for full command output.

첫번째 시도: brew와 Xcode reinstall

상사와 debug 페어프로를 진행하다가 찾은 스택 오버플로우의 해답.

이 사람은 brew의 symlink가 꼬여서 그런거니 brew를 다시 넣으라 했고

Turned out that I had a bunch of weird symlinks in my /usr/local/include folder. I removed the whole folder and reinstalled Homebrew and everything went back to normal again.

이 사람은 Xcode의 path가 꼬여서 그런거니 Xcode를 다시 넣으라 했다.

Found the solution through a swift forum it worked with me it seems that somehow the commandline tools got corrupted or just deprecated.
TL;DR;
Remove CommandLine Tools directory: sudo rm -rf /Library/Developer/CommandLineTools
Recreate with: sudo xcode-select -s /Applications/Xcode.app

둘 다 다시 넣어본 결과 전혀 상관이 없었다.
시간만 엄청 잡아먹으니 마지막까지 안되면 그 때 시도해보는 것이 좋겠다.

두번째 시도: Python3.x를 reinstall

다음날, 같은 팀 동료들이 조언을 주었다.

새로 clone 해봐라

왜냐 하면, 다른 팀원들 로컬 환경에서는 동일한 리포지토리 (동일한 pipenv 환경) 에서 문제 없이 libmfimplicit이 설치되었기 때문이다.
하지만 여전히 에러는 났다.
참고로 이 리포지토리의 Python은 3.8.4였다.

그렇다면 텅 빈 폴더를 만들어 implicit을 설치해봐라

아래 command로 진행했다.

$ cd ..
$ mkdir test_implicit
$ cd test_implicit
$ pipenv install implicit 

그러자 아무 이상 없이 설치에 성공한 것이 아닌가.

파이썬 버전을 확인해보니 3.9.1이었다.

$ which python3
3.9.1

그렇다면 Python3.8.4로 버전을 바꾸어 해보자.

$ rm Pipfile*
$ pipenv --python 3.8.4
$ 
$ pipenv install implicit

그러자 에러가 났다!

업그레이드를 해야 해결되는 문제는 아니기 때문에 (다른 팀원들은 3.8.4에서 문제가 없었기 때문에) Python3.8.4의 path가 뭔가 단단히 꼬인 것이라는 결론에 도달했다.

Python3.x를 reinstall해보자

$ brew uninstall python3
$ brew install python3
$ pyenv install 3.8.4
$ cd test_implicit
$ rm Pipfile*
$ pipenv --python 3.8.4
$ pipenv install implicit

성공

드디어 성공했다! 이거 해결하는데 3일 걸렸다.
기쁨의 순간을 보시라.

Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
Installing libmf...
✔ Installation Succeeded 
Installing implicit...
✔ Installation Succeeded 
Pipfile.lock (4bad4d) out of date, updating to (5a861c)...
Locking [dev-packages] dependencies...
✔ Success! 
Locking [packages] dependencies...
✔ Success! 
Updated Pipfile.lock (5a861c)!
Installing dependencies from Pipfile.lock (5a861c)...
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 43/43 — 00:00:19
jungwon.choi@:~/git_repositories/newspicks/newspicks-feed-engine|feature/ub_implicit_als_with_64_dim⚡ ⇒  which python3
/Users/jungwon.choi/.local/share/virtualenvs/newspicks-feed-engine-fcIudhtP/bin/python3