IT/디버깅

[디버깅] 구글 코랩 tensorflow light install 이슈 해결

happy_life 2023. 7. 20. 16:20

Can't install tflite-model-maker from pip 에러가 발생하여 해결하는 과정을 적었습니다.

INFO: pip is looking at multiple versions of tensorflow to determine which version is compatible with other requirements. This could take a while. 이슈

 

 

 

1. tensorflow light 다운로드 이슈 원인

Requirement already satisfied: pycocotools in /usr/local/lib/python3.10/dist-packages (from tf-models-nightly->tflite-model-maker) (2.0.6) Collecting pyyaml<6.0,>=5.1 (from tf-models-nightly->tflite-model-maker) Using cached PyYAML-5.4.1.tar.gz (175 kB) Installing build dependencies ... done error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully.  exit code: 1

Installing build dependencies ... done error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully.

 

-- 여러 dependency 들의 호환성문제로 여러가지 버전의 dependency를 다운받게 되는데 이 것들 간의 상호 호환관계가 문제 생기거나 혹은 여러 버전의 dependency 중 특정 dependency 하나가 다운로드 되지 못해 발생하는 문제입니다.

 

2. tensorflow light 해결시도

1. !pip install -q tflite-model-maker-nightly 버전으로 다운 시도 (실패)

2. python 3.8로 버전 다운 (실패)

 

 

!update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8

!update-alternatives --config python3
 

 

추가 에러1

pip가 없다는 에러가 발생 -> 설치 

 

추가 에러2

No module named distutils.util 에러가 발생 

원인: 우분투와 버전 호환이 되지 않아 생기는 문제

distutils.cmd 에러

 

해결과정

1. distutils 다운로드 시도 

-> 기존 코렙의 3.10.6 버전 distutils가 존재하여 다운로드 받아지지 않았습니다.

 

2. distutils만 따로 삭제하는 것보다는 한번에 기존의 python 3.10.6을 삭제하고 python 3.8을 설치하는 것이 좋겠다는 판단을 하였습니다. 따라서 아래의 코드로 삭제를 진행하였습니다.

!sudo apt-get remove python3.10

 

3. pip가 존재하지 않아 install 하였습니다.

!sudo apt-get update
!sudo apt-get install python3-pip

 

4. 여전히 똑같은 문제가 발생하여 확인해보니 distutils 3.10.6은 지워진 상태가 아니었습니다.

dpkg -l python3-distutils

따라서 아래의 코드로 지웠습니다.

!sudo apt-get remove python3-distutils

 

 

5. 초기화를 위해 python3.8을 재설치해주고 distutils를 다운받았습니다.

!sudo apt-get --reinstall install python3.8
!sudo apt-get install python3.8-distutils


 

6. pip를 설치하였습니다.

!sudo apt-get install python3-pip

 

 

 

추가에러3

Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead

 

이 에러는 설치의 권한 문제로 발생하는 것입니다. 이를 해결하기 위해서는 --root-user-action=ignore의 명령어를 작성해야 하지만 google colab에서는 지원하지 않습니다.

 

 

3. 기존 version의 python에서 문제 해결 시도(실패)

 

1. 에러 코드 다시 보기

Requirement already satisfied: pycocotools in /usr/local/lib/python3.10/dist-packages (from tf-models-nightly->tflite-model-maker) (2.0.6) Collecting pyyaml<6.0,>=5.1 (from tf-models-nightly->tflite-model-maker) Using cached PyYAML-5.4.1.tar.gz (175 kB) Installing build dependencies ... done error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully. exit code: 1

Installing build dependencies ... done error: subprocess-exited-with-error × Getting requirements to build wheel did not run successfully.

 

install pyyaml 과 관련하여 이슈가 발생한 것이었습니다.

 

 

해결과정

1. pip upgrade(실패)

!pip install --upgrade pip

23.1.2 -> 23.2로 업그레이드 해보았습니다.

 

2. pip cache를 지우고 다시 다운로드 받아보았습니다.(실패)

!pip cache purge

 

3. tensorlfow version 업그레이드 (실패) 

!pip install --upgrade tensorflow

 

4.  tflite 업그레이드 (실패)

!pip install --upgrade tflite

 

5.  setuptool 업그레이드(실패)

!pip install --upgrade setuptools wheel

 

6. pyyaml 삭제 후 시도(실패)

 

!pip install tflite-model-maker

 

7. 컴퓨터 재부팅

컴퓨터를 재부팅했더니 pyyaml이 정상적으로 download 되었으나, 

Collecting absl-py<0.11>=0.10.0 Downloading absl-py-0.9.0.tar.gz (104 kB)

error: subprocess-exited-with-error × python setup.py egg_info did not run successfully. exit code: 1 ╰─> See above for output.

 

다른 dependency에서 에러가 발생하였습니다.

이상했던 점은 0.11을 이미 다운받았음에도 불구하고 match 되는 dependency를 위해 0.9를 다운받으려고 시도했다는 점입니다.

INFO: pip is looking at multiple versions of numpy to determine which version is compatible with other requirements. This could take a while.

 

 

8. 특정 version의 model-maker로 지정하여 install

 

이러한 것을 찾아보니 python이나 pip 그리고 tflite-model-maker가 버전 호환 issue가 있어서 발생할 수 있는 문제라고 합니다. 따라서 이를 해결하기 위해 tflite-model-maker==0.3.0으로 specific하게 지정해주고 install을 시도하였습니다.

 

!pip install tflite-model-maker==0.3.0

하지만 여전히 같은 문제가 발생하였습니다.

 

 

4. colab conda 가상환경 사용 python version 3.7(성공)

성공

 

!pip install -q condacolab
import condacolab
condacolab.install()

import condacolab
condacolab.check()

!conda create --name myenv python=3.7 -y

!whereis pip

!/usr/local/envs/myenv/bin/pip --version

!source activate myenv; python --version

! source activate myenv; pip --version

! source activate myenv; pip cache purge
! source activate myenv; pip install pyyaml==6.0
! source activate myenv; pip install tflite-model-maker

 

 

 

참고

https://github.com/tensorflow/tensorflow/issues/59855