코드 깎는 PM

Linux/Ubuntu Error Log #1 - DVC 설치 중 python 설치와 업데이트 본문

ML Ops/Error Log

Linux/Ubuntu Error Log #1 - DVC 설치 중 python 설치와 업데이트

PM스터 2023. 1. 22. 16:24
반응형

MLOps 공부 중 Data의 Version을 관리해주기 위한 툴인 DVC를 설치하는 중에 만난 에러를 고치는 여정이다. 

DVC = DataVersionControl

1) Alternative 명령어를 활용한 파이썬 버전 변경

Ubuntu 환경에서 python을 사용하면 기본적을 python 2.7.17이 깔려있다. 

하지만 급속한 파이썬 생태계의 발전으로... 파이썬 2.7을 사용하려 한다면 많은 버전 이슈와 직면하게 된다. 

때문에 ubuntu상의 alternative 명령어를 활용해서 파이썬 버전을 수정해보도록 하자. 

 

(1) 버전 및 위치 확인 

1. python -V 혹은 python --version을 사용하면 현재 사용중인 python의 버전을 확인할 수 있다. 

2. which 코드를 사용하면 현재 사용중인 파이썬의 저장위치를 확인할 수 있다. 

$ python -V
Python 2.7.14

$ which python
/usr/bin/python

ls -al /usr/bin/python 코드를 통해 해당 파일이 가리키는 파일을 확인할 수 있다. 

$ ls -al /usr/bin/python
lrwxrwxrwx 1 root root 24  4월 18 19:28 /usr/bin/python -> /usr/bin/python2.7

ls /usr/bin/을 통해 해당 위치에 깔려있는 python들의 버전들을 확인할 수 있다. 

$ ls /usr/bin/ | grep python
python
python2
python2.7
python3
python3.6
.....

(2) 버전 업데이트

update-alternatives --install<link> <name> <path> <priority>의 순으로 input 값을 요구한다. 

만약 priority를 1로 한가지 alternative만을 설정한다면 아래와 같이 설정된  alternative를 바로 auto mode로 설정하여 사용중인 파이썬의 버전을 업데이트 한다.  

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python (python) in auto mode

만약 아래와 같이 2가지 이상의 alternative를 사용한다면,   

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2

--config python 을 실행하여 아래와 같이 대안들이 나오는 것을 확인할 수 있으며, 이때 사용할 alternative 순번을 클릭하여 실행하면 된다.

$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.6   2         auto mode
  1            /usr/bin/python2.7   1         manual mode
  2            /usr/bin/python3.6   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

이후 python --version을 사용하여 버전을 확인해보면 정상적으로 버전이 바뀐 것을 확인할 수 있다.

$ python --version
Python 3.6.9

(2) 파이썬 3.9 버전 install 

하지만 어림도 없지 우리의 dvc는 3.6.9정도 수준으로는 쉽게 깔려주지 않는다.. 

(dvc[all] 에서[all] 은 dvc 의 remote storage 로 s3, gs, azure, oss, ssh 모두를 사용할 수 있도록 관련 패키지를 함께 설치하는 옵션이다.)

$ pip install dvc[all]
Error: pygit2 requires Python '>=3.7' but the running Python is 3.6.9

때문에 python3.9를 install해주기로 한다. 

(P.S. 앞서 바로 python3.9를 바로 다운로드 하지 않은 이유는 왜인지는 모르게 python2.7버전에서 바로 install을 하는 경우 자꾸 Error가 발생하였기 때문이다. python3.6으로 변경한 후 install하면 정상적으로 install이 된다. 왜일까..)

$ sudo apt install python3.9

그리고 다시 실행하면 다시금 Error들을 만난다. 

$ pip install dvc[all]
ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.9/distutils/__init__.py)

pip가 작동하지 않았던 오류를 해결하기 위해서 pip도 다시 install해주고, distutilssysconfig를 install해준다. 

$ sudo apt install python3-pip
$ sudo apt install python3.9-distutils
$ python3 -c "from distutils import sysconfig"

하지만 이후에도 아래와 같은 에러가 발생한다. 

$ pip install dvc[all]
AttributeError: 'HTMLParser' object has no attribute 'unescape'

새로 설치한 Python3.9버전에 setuptool들을 업데이트하지 않아서 발생한 오류이다. setuptool들을 업데이트해보자.

$ pip3 install --upgrade setuptools
$ pip install --upgrade pip
$ pip install -U setuptools

업데이트 이후에는 정상적으로 dvc가 install되는 것을 확인할 수 있다.

그럼에도 불구하고 dvc --version을 실행하면 error가 나타나는 것을 볼 수 있는데, 이 경우에는 Ubuntu를 재실행하여 dvc --version을 실행하면 해결되는 것을 확인할 수 있습니다.

$ dvc --version

Command 'dvc' not found, did you mean:

  command 'rvc' from deb vtgrab
  command 'dfc' from deb dfc
  command 'dtc' from deb device-tree-compiler
  command 'drc' from deb drc
  command 'dc' from deb dc
  command 'svc' from deb daemontools
  command 'duc' from deb duc
  command 'duc' from deb duc-nox

Try: sudo apt install <deb name>

아래는 Ubuntu를 재실행한 후 version을 확인해본 결과입니다. 

$ dvc --version
Data Version Control

optional arguments:
  -q, --quiet        Be quiet.
  -v, --verbose      Be verbose.
  -h, --help         Show this help message and exit.
  -V, --version      Show program's version.
  --cd <path>        Change to directory before executing.

Available Commands:
  COMMAND            Use `dvc COMMAND --help` for command-specific help.
    init             Initialize DVC in the current directory.
    get              Download file or directory tracked by DVC or by Git.
    get-url          Download or copy files from URL.
    destroy          Remove DVC files, local DVC config and data cache.
    add              Track data files or directories with DVC.
    remove           Remove stages from dvc.yaml and/or stop tracking files or directories.
    move             Rename or move a DVC controlled data file or a directory.
    unprotect        Unprotect tracked files or directories (when hardlinks or symlinks have been enabled with `dvc config cache.type`).
    run              Generate a dvc.yaml file from a command and execute the command.
    repro            Reproduce complete or partial pipelines by executing their stages.
    pull             Download tracked files or directories from remote storage.
    push             Upload tracked files or directories to remote storage.
    fetch            Download files or directories from remote storage to the cache.
    status           Show changed stages, compare local cache and a remote storage.
    gc               Garbage collect unused objects from cache or remote storage.
    import           Download file or directory tracked by DVC or by Git into the workspace, and track it.
    import-url       Download or copy file from URL and take it under DVC control.
    config           Get or set config options.
    checkout         Checkout data files from cache.
    remote           Set up and manage data remotes.
    cache            Manage cache settings.
    metrics          Commands to display and compare metrics.
    params           Commands to display params.
    install          Install DVC git hooks into the repository.
    root             Return the relative path to the root of the DVC project.
    list             List repository contents, including files and directories tracked by DVC and by Git.
    freeze           Freeze stages or .dvc files.
    unfreeze         Unfreeze stages or .dvc files.
    dag              Visualize DVC project DAG.
    commit           Record changes to files or directories tracked by DVC by storing the current versions in the cache.    completion       Generate shell tab completion.
    diff             Show added, modified, or deleted data between commits in the DVC repository, or between a commit and the workspace.
    version (doctor)
                     Display the DVC version and system/environment information.
    update           Update data artifacts imported from other DVC repositories.
    plots            Commands to visualize and compare plot metrics in structured files (JSON, YAML, CSV, TSV).
    stage            Commands to list and create stages.
    experiments (exp)
                     Commands to run and compare experiments.
    check-ignore     Check whether files or directories are excluded due to `.dvcignore`.

 

 

 

 

Reference: 

https://codechacha.com/ko/change-python-version/

https://codechacha.com/ko/ubuntu-install-python39/

https://jjeongil.tistory.com/1274

https://rottk.tistory.com/entry/Ubuntu-Python3-%EC%B5%9C%EC%8B%A0-%EB%B2%84%EC%A0%84-%EC%84%A4%EC%B9%98%ED%95%98%EA%B8%B0

https://askubuntu.com/questions/1292972/importerror-cannot-import-name-sysconfig-from-distutils-usr-lib-python3-9

https://flyburi.com/614

https://stackoverflow.com/questions/74621173/python3-10-6-cant-pip-install-things-error-subprocess-exited-with-error

반응형

'ML Ops > Error Log' 카테고리의 다른 글

Linux/Ubuntu Error Log #2 - mlflow 버전 문제 해결  (0) 2023.01.22
Comments