www.instrumedley.net
これのつづきです。
環境
$ cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
$ uname -r
3.10.0-862.9.1.el7.x86_64
$ which python
/bin/python
$ python -V
Python 2.7.5
$ id
uid=1000(testuser) gid=1000(testuser) groups=1000(testuser)
プロジェクトの条件
ここでは、 Webアプリケーションフレームワークである flask
を例としてインストールします。
Python は 3.7.0 をインストールします。
また、アンインストールの例に tqdm
を利用します。
python 3.7 をビルドするために必要なパッケージをインストール
$ sudo yum groupinstall -y "Development Tools"
$ sudo yum install -y readline-devel zlib-devel bzip2-devel sqlite-devel openssl-devel libXext.x86_64 libffi-devel
Python 3.7.0 をビルドするために必要なパッケージをインストールしておきます。
pipenv の使い方
プロジェクトディレクトリの作成と python-3.7 のインストール
$ mkdir -p ~/green
$ cd ~/green
$ pipenv --python 3.7.0
Warning: Python 3.7.0 was not found on your system...
Would you like us to install CPython 3.7.0 with pyenv? [Y/n]:
(snip)
Creating a Pipfile for this project...
$ ls
Pipfile
$ pyenv versions
* system (set by /home/testuser/.pyenv/version)
3.7.0
実行
run
は与えられたコマンドが仮想環境内でじっこうされます。shell
は仮想環境が有効化されたシェルを起動されます。
$ pipenv run python -V
Python 3.7.0
$ pipenv shell
(green-jYRliImI) $ python -V
Python 3.7.0
(green-jYRliImI) $ exit
exit
python パッケージのインストールとアンインストール
tqdm のインストールとアンインストール
$ cd ~/green
$ pipenv install tqdm
Installing tqdm...
(snip)
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
$ ls
Pipfile Pipfile.lock
$ pipenv uninstall tqdm
Un-installing tqdm...
(snip)
Removing tqdm from Pipfile...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Updated Pipfile.lock (a65489)!
flask のインストールとpythonパッケージリスト
$ pipenv install flask
$ pipenv graph
Flask==1.0.2
- click [required: >=5.1, installed: 6.7]
- itsdangerous [required: >=0.24, installed: 0.24]
- Jinja2 [required: >=2.10, installed: 2.10]
- MarkupSafe [required: >=0.23, installed: 1.0]
- Werkzeug [required: >=0.14, installed: 0.14.1]
$ pipenv run pip freeze -l
click==6.7
Flask==1.0.2
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
Werkzeug==0.14.1
仮想環境のディレクトリ情報
$ pipenv --venv
/home/testuser/.local/share/virtualenvs/green-jYRliImI
仮想環境の削除
$ pipenv --rm
Removing virtualenv (/home/testuser/.local/share/virtualenvs/green-jYRliImI)...
completion
の設定
$ echo 'eval "$(pipenv --completion)"' >> ~/.basrh_profile
$ source ~/.bash_profile
プロジェクトのコピーにつづきます。
www.instrumedley.net