-
Colab에서 모듈 버전이 갱신 되지 않을 때Programming (Others)/각종 에러 해결 일지 2023. 2. 9. 19:04
배경
코드를 돌리다 버전 충돌이 나서, pygments를 더 윗버전으로 깔려고 했다.
- 현재 pygments 버전 확인
input
import pygments pygments.__version__
output
2.6.1
- 새로운 버전 설치
!pip install jedi # 얘 안해주면 pip warning 어쩌고 뜨는듯 !pip uninstall pygments==2.6.1 !pip install pygments==2.14.0
문제 상황
- 다시 버전 확인
input
import pygments pygments.__version__
output
2.6.1
버전이 그대로다...
해결 방법
새로운 버전의 모듈을 설치했으면, runtime을 재시작해주어야 한다.
runtime을 restart할 경우 local variable 같은 정보는 사라지지만, 현재 환경 정보 (내가 설치한 모듈 버전 등) 은 갱신되게 된다.
이 이슈에 대해 자세히 찾아보기 위해 스택 오버플로우를 찾아봤는데... 확실한 건 아니고 추측성 글을 찾았다.
Need to restart runtime before import an installed package in Colab
I am trying to install and use an existing python package in Google Colab. For this, I download the code from Github in Colab and install the package, but when trying to import the installed packag...
stackoverflow.com
It seems that everything except simple !pip installs seem to not get included in colab's module registry except after a runtime restart. Likely, colab has a fairly naive way of keeping track of available modules. You also have to restart the runtime if you import a different version of a previously installed package.
Probably they just have a script that appends the metadata for piply installed packages to a list-like object during runtime. And imports just search from the top of the list (which is why the restart is required for diff versions of packages).
However, when a new runtime is started, the list-like registry is initialized and populated by searching the relevant directories.runtime 동안 기존에 설치된 package 메타데이터를 list-like object에 저장해두고, import 명령어를 받을 경우 list 맨 앞부터 찾는다. (이렇게 때문에 기존 버전이 로드되는 것으로 보인다.)
runtime이 재시작될 경우, 이 object는 초기화된 후 연관된 디렉토리를 탐색하여(내가 깔아둔 다른 버전을 말하는 듯?) 채워진다.
뭐 어디까지나 추측성이지만 이런 원리가 사실이라면 어느정도 납득이 된다..!
'Programming (Others) > 각종 에러 해결 일지' 카테고리의 다른 글
[Visual Studio] 자동 완성 시 ;(세미콜론), /(슬래시) 등의 입력이 무시되는 문제 (0) 2022.02.03 [Anaconda] tensorflow 사용 중 만난 세 가지 에러 (0) 2022.01.26 pip이 있었는데요, 없었습니다 (pip 새로 설치) (0) 2022.01.26 [Git] Authentication failed 문제. (git Token) (0) 2022.01.26 [linux/ubuntu] mecab-ko-dic을 설치하기 위해 고군분투한 일(..) (0) 2021.05.29