Launguage

Python 가상환경 설정(WSL2 Ubuntu)

Somaz 2023. 10. 10. 23:48
728x90
반응형

Overview

WSL2 Ubuntu Python 가상환경 설정 방법에 대해서 알아보려고 한다.

 

출처 : https://github.com/pyenv/pyenv

 


Python 가상환경 설정

 

ubuntu 버전 확인

lsb_release -a
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:        20.04
Codename:       focal

 

 

Dependency 설치(Ubuntu/Debian)

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

 

pyenv 설치 및 Python 버전 구성

 

pyenv 설치

# pyenv 설치가능 버전확인
pyenv install --list

# pyenv 설치
curl https://pyenv.run | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc

# python 버전확인
python3
Python 3.8.10 (default, May 26 2023, 14:05:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

python2
Python 2.7.18 (default, Jul  1 2022, 12:27:04)
[GCC 9.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

 

 

Python 버전 구성

# python version 셋팅
pyenv global 3.8.10 2.7.18
pyenv: version `3.8.10' not installed

# error 발생 시 설치
pyenv install 3.8.10
pyenv install 2.7.18

# python version 셋팅
pyenv global 3.8.10 2.7.18

 

 

가상환경 설정

  • python2
  • python3

 

 

pip version 확인

pip2 --version
pip 20.3.4 from /home/somaz/.pyenv/versions/2.7.18/lib/python2.7/site-packages/pip (python 2.7)

pip3 --version
pip 21.1.1 from /home/somaz/.pyenv/versions/3.8.10/lib/python3.8/site-packages/pip (python 3.8)

 

virtualenv 설치

sudo apt install virtualenv

 

 

가상환경 설정(python2)

virtualenv -p $(pyenv which python2) somaz
created virtual environment CPython2.7.18.final.0-64 in 148ms
  creator CPython2Posix(dest=/home/somaz/somaz, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/somaz/.local/share/virtualenv/seed-app-data/v1.0.1.debian.1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator

# activate
source somaz/bin/activate

# deactivate
(somaz) somaz@BOOK-CRMT0FFGUS:~$ deactivate

 

 

가상환경 설정(python3)

virtualenv -p $(pyenv which python3) somaz
created virtual environment CPython3.8.10.final.0-64 in 182ms
  creator CPython3Posix(dest=/home/somaz/somaz, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/somaz/.local/share/virtualenv/seed-app-data/v1.0.1.debian.1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

# activate
source somaz/bin/activate

# deactivate
(somaz) somaz@BOOK-CRMT0FFGUS:~$ deactivate

 

 


Reference

https://github.com/pyenv/pyenv

https://jinmay.github.io/2019/03/16/linux/ubuntu-install-pyenv-1/

https://eyeballs.tistory.com/571

728x90
반응형