티스토리 뷰

문제 상황(관찰)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
user$ python
Python 2.7.10 (default, Oct  6 201722:29:07
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help""copyright""credits" or "license" for more information.
>>> import weakref
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 14, in <module>
    from _weakref import (
ImportError: cannot import name _remove_dead_weakref
>>>
 
root$ python
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 29 201820:59:26
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help""copyright""credits" or "license" for more information.
>>> import weakref
>>>
 
cs


상황 파악

  • 차이점 : user와 root가 서로 실행한 python의 버전
  • 현재 환경에 총 2개의 python이 있는데, user는 system python을 실행하고 root는 직접 설치한 python을 실행
  • 가설 : system python인 2.7.10에서 weakref를 import하려고 하면 오류가 나는 것 같다.
  • 결과 예측 : 그렇다면 user에서 root가 실행한 python을 실행한다면 오류가 발생하지 않을 것이다.


가설 시험 및 증명

1
2
3
4
5
6
7
user$ /usr/local/bin/python
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 29 201820:59:26
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help""copyright""credits" or "license" for more information.
>>> import weakref
>>> 
 
cs
  • root가 실행하고 있는 python을 직접 실행시켜 확인해본 결과, 잘 된다.


가설 반증 상황

1
2
3
4
5
6
root$ /usr/bin/python
Python 2.7.10 (default, Oct  6 201722:29:07
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help""copyright""credits" or "license" for more information.
>>> import weakref
>>> 
cs
  • root로 user가 실행하고 있는 python을 실행했더니, 이것도 잘 된다. 
  • 버전의 문제라고 생각하였으나, python 버전의 문제만은 아닌 듯 하다.


결론

  • 원인 도출 : 자세히 알 수 없음, python 들이 모듈을 어떻게 참조하고 있는지 확인해 봐야 알 듯 하다.
  • 해결 방안 : 근본적인 해결 방안은 아직 찾지 못 하였다. 찾게 되면 추가...
  • 대체 해결 방안 : 우선 설치된 python의 버전을 잘 확인해 보고, 문제가 발생하지 않는 python을 찾아 사용한다.


추가

  • python 전부 삭제
    • Storage - Application - remove Python
    • brew rm python
  • brew doctor : Warning 내용 전부 수정
  • brew install python


참고

  • https://stackoverflow.com/questions/47658596/strange-mixing-of-system-homebrew-python-with-lldb


댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
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