시리즈 목록

윈도우(windows) WSL Ubuntu에 virtualenv 설치 및 vscode 연동
윈도우(windows) WSL Ubuntu에 pyenv 설치
윈도우(windows) WSL Ubuntu에 도커(Docker) 설치
윈도우(windows) WSL에 Ubuntu 20.04 LTS 추가 설치
윈도우(windows) WSL 명령어
윈도우(windows) WSL 설치 및 Ubuntu 구동

 

Ubuntu 22.04 LTS에는 python3가 설치되어있다. pip, venv는 설치되어 있지 않음

gabriel@NB-15052600:~$ python -V
Command 'python' not found, did you mean:
  command 'python3' from deb python3
  command 'python' from deb python-is-python3
gabriel@NB-15052600:~$ python3 -V
Python 3.10.6
gabriel@NB-15052600:~$ python3 -m pip
/usr/bin/python3: No module named pip
gabriel@NB-15052600:~$

 

1.pyenv 설치

 

참고 https://github.com/pyenv/pyenv

git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc

 

 

gabriel@NB-15052600:~$ pyenv install 3.11.3
Downloading Python-3.11.3.tar.xz...
-> https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tar.xz
Installing Python-3.11.3...

BUILD FAILED (Ubuntu 22.04 using python-build 2.3.17-10-g920ef145)

Inspect or clean up the working tree at /tmp/python-build.20230515214905.2289
Results logged to /tmp/python-build.20230515214905.2289.log

Last 10 log lines:
checking for pkg-config... no
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "linux"
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/python-build.20230515214905.2289/Python-3.11.3':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
gabriel@NB-15052600:~$

설치 에러가 발생할경우 apt 업데이트를 수행한다.

sudo apt update
sudo apt install \
    build-essential \
    curl \
    libbz2-dev \
    libffi-dev \
    liblzma-dev \
    libncursesw5-dev \
    libreadline-dev \
    libsqlite3-dev \
    libssl-dev \
    libxml2-dev \
    libxmlsec1-dev \
    llvm \
    make \
    tk-dev \
    wget \
    xz-utils \
    zlib1g-dev

 

gabriel@NB-15052600:~$ pyenv install 3.11.3
Downloading Python-3.11.3.tar.xz...
-> https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tar.xz
Installing Python-3.11.3...
Installed Python-3.11.3 to /home/gabriel/.pyenv/versions/3.11.3
gabriel@NB-15052600:~$

 

원하는 버전 지정

 

pyenv local 3.11.3  <어플리케이션별로 파이썬 버전을 설정하는데 사용>

pyenv global 3.11.3 <전역 파이썬 버전을 설정>

gabriel@NB-15052600:~$ pyenv --versions
pyenv: no such command `--versions'
gabriel@NB-15052600:~$ pyenv versions
* system (set by /home/gabriel/.pyenv/version)
  3.11.3
gabriel@NB-15052600:~$ pyenv local 3.11.3
gabriel@NB-15052600:~$ pyenv versions
  system
* 3.11.3 (set by /home/gabriel/.python-version)
gabriel@NB-15052600:~$
gabriel@NB-15052600:~$ python -V
Python 3.11.3
gabriel@NB-15052600:~$

 

 

파이썬 버전이 제도로 적용도었는지 확인

gabriel@NB-15052600:~$ pyenv which python
/home/gabriel/.pyenv/versions/3.11.3/bin/python
gabriel@NB-15052600:~$

 

 

+ Recent posts