Python 虛擬環境 101

王亮博(亮亮)2014-06-19

Taipei.py, 2014-06-19

Python 虛擬環境 101

王亮博 (亮亮)
Shared under CC 4.0 BY license

Esc to overview
← → to navigate

About Me

Why 101?

相信很多人覺得很簡單

Life is harder on Windows ... By PyConAPAC 2015, do one thing with Python that you've never done before.

Jessica McKellar, PyCon APAC 2014

Q 如果在○○系統上要怎麼安裝?

這問題很難又很好回答……先用 Vagrant 開虛擬機

Python 基本的環境

你需要 Python + Setuptools + Pip,底下用 Python 3.4 舉例

sudo apt-get install python3 python3-pip
pip3 freeze
# requests==2.3.0
# wheel==0.23.0
# ... 這些是系統有用到的套件

Python 套件安裝

由 Debian 維護,(但) …

使用虛擬環境 virtualenv

有人會提到 pyvenv

Virtualenv 使用

sudo apt-get install python-virtualenv  # 裝在 2.7 上
virtualenv venv_foo  # 建立一個超然的資料夾
source venv_foo/bin/active
(venv_foo)   # 會在虛擬環境裡
(venv_foo) deactivate

virtualenv -p /path/to/python2.7  # 指定不同的 python 位置

獨立之後…然後咧

World of pyenv

Thank You!

Fork me on Github