IT Talks

Python3 가상 ν™˜κ²½ 생성

OkOJJ 2022. 9. 22. 13:33

venv λͺ¨λ“ˆμ€ 자체 μ‚¬μ΄νŠΈ 디렉터리λ₯Ό κ°–λŠ” κ²½λŸ‰ “가상 ν™˜κ²½”을 λ§Œλ“€κ³ , μ„ νƒμ μœΌλ‘œ μ‹œμŠ€ν…œ μ‚¬μ΄νŠΈ λ””λ ‰ν„°λ¦¬μ—μ„œ 격리할 수 μžˆλ„λ‘ μ§€μ›ν•©λ‹ˆλ‹€. 각 가상 ν™˜κ²½μ€ κ³ μœ ν•œ 파이썬 λ°”μ΄λ„ˆλ¦¬(이 ν™˜κ²½μ„ λ§Œλ“œλŠ” 데 μ‚¬μš©λœ λ°”μ΄λ„ˆλ¦¬ 버전과 μΌμΉ˜ν•¨)λ₯Ό 가지며 μžμ‹ μ˜ μ‚¬μ΄νŠΈ 디렉터리에 λ…λ¦½μ μœΌλ‘œ μ„€μΉ˜λœ 파이썬 νŒ¨ν‚€μ§€ 집합을 κ°€μ§ˆ 수 μžˆμŠ΅λ‹ˆλ‹€.

κ°€μƒν™˜κ²½ 생성

$ python3 -m venv /home/myhome/venv

* μ§€μ •ν•œ 디렉토리에 가상 ν™˜κ²½ 생성 (λ¦¬λˆ…μŠ€ κΈ°μ€€)

* μ‹€ν–‰ ν›„ μ΄λž˜μ™€ 같은 였λ₯˜κ°€ λ°œμƒν•œλ‹€λ©΄ --without-pip μ˜΅μ…˜μœΌλ‘œ pip λŠ” λ³„λ„λ‘œ μ„€μΉ˜ν•΄ μ€€λ‹€.

Error: Command '['/home/ojj/venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

 

$ python3 -m venv /home/myhome/venv --without-pip
$ source ./venv/bin/activate
$ curl https://bootstrap.pypa.io/get-pip.py | python

 

 

κ°€μƒν™˜κ²½ 적용

$ source venv/bin/activate

 

κ°€μƒν™˜κ²½ 적용 확인

(venv) myhome@myserver:~$ which python3
/home/myhome/venv/bin/python3

 

κ°€μƒν™˜κ²½ 적용 ν•΄μ œ

(venv) myhome@myserver:~$ deactivate
myhome@myserver:~$

 

 

κ΄€λ ¨ λ¬Έμ„œ

* https://docs.python.org/ko/3/library/venv.html
* https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/

 

728x90