LoginSignup
2
5

More than 5 years have passed since last update.

CentOS7 で Python 仮想環境を作る

Last updated at Posted at 2019-01-20

はじめに

CentOS7 で Python3.6、Python2.7 の仮想環境を作る方法をまとめておきます。

Python3.6 で仮想環境を作る

CentOS7 の場合 epel から Python 3.6 をインストールできる。
Python3.3以降、venvが標準パッケージである。
venvで仮想環境を作る。

Python3.6 + venv を入れる

yum install epel-release -y
yum-config-manager --disable epel
yum install --enablerepo="epel" python36 -y

仮想環境を作る

mkdir -pv $HOME/.venv
python36 -mvenv $HOME/.venv

仮想環境を有効にする

source $HOME/.venv/bin/activate

仮想環境を終了する

deactivate

Python2.7 で仮想環境を作る

virtualenv を使う。

virtualenv を入れる

yum install python-virtualenv -y

仮想環境を作る

yum install python-virtualenv -y
virtualenv -p /usr/bin/python2.7 $HOME/.virtualenv

仮想環境を有効にする

source $HOME/.virtualenv/bin/activate

仮想環境を終了する

deactivate

参考文献

virtualenv
https://virtualenv.pypa.io/en/latest/

venv
https://docs.python.org/3/library/venv.html

@k8uwall さんコメント:
https://qiita.com/kumarstack55/items/0babae3f4f7180985217#comment-a889976a05d9cf81c5bd

python-virtualenvをインストールしなくてもpython36だけ入れればvenv使えます。

2
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
5