Python pipenv (pyenv+pip+vscode)
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
] [
Trackback(0)
]
開始行:
#contents
*これは何? [#g2a5c01b]
-公式サイト: https://github.com/pypa/pipenv
-Pipenv = pip + pyenv
--pip : Python のライブラリを管理する機構
--pyenv : アプリケーション実行環境をアプリケーションごと...
-Java や Node にはもともと持っている機構
*インストール [#c5d26000]
$ python3 --version
Python 3.5.3
$ sudo apt install python3-pip
$ pip3 -V
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
$ pip3 install --user --upgrade pipenv
これで ~/.local/bin/pip/ に pipenv がインストールされて、...
最後に、PATH に ~/.local/bin を追加する (最初から入ってい...
- ~/.profile
#code(bash){{{
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin":$PATH
fi
}}}
$ source ~/.profile
$ pipenv --version
pipenv, version 2018.11.26
*pipenv プロジェクトの作成 [#n95f37b8]
-プロジェクトの初期化
$ mkdir pySample
$ cd pySample
$ mkdir pySample
$ mkdir docs
$ mkdir notes
$ mkdir tests
$ touch LICENSE
$ touch README.md
$ touch pySample/__init__.py
$ touch tests/__init__.py
$ pipenv --three
Creating a virtualenv for this project…
Pipfile: /home/atsushihondoh/python/pySample/Pipfile
Using /usr/bin/python3.5m (3.5.3) to create virtualenv…
...
-標準的なプロジェクト構成
$ tree
.
├── LICENSE
├── Pipfile
├── Pipfile.lock
├── README.md
├── docs
├── notes
├── pySample
│ └── __init__.py
└── tests
└── __init__.py
-依存関係は Pipfile に記載される
#code(python){{{
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
[requires]
python_version = "3.5"
}}}
-依存ライブラリの指定
$ pipenv install numpy
-開発用ライブラリの指定 (テストやコード整形のためのライブ...
$ pipenv install --dev autopep8 flake8
-Pipfile は次のようになります
#code(python){{{
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
autopep8 = "*"
flake8 = "*"
[packages]
numpy = "*"
[requires]
python_version = "3.5"
}}}
-より詳細な依存ライブラリの情報は Pipfile.lock に記述され...
#code(python){{{
{
"_meta": {
"hash": {
"sha256": "1c1d943573ca6420ef250bbdcbea2b850b...
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.5"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"numpy": {
"hashes": [
"sha256:1786a08236f2c92ae0e70423c45e1e627...
"sha256:17aa7a81fe7599a10f2b7d95856dc5cf8...
"sha256:20b26aaa5b3da029942cdcce719b363db...
"sha256:2d75908ab3ced4223ccba595b48e538af...
"sha256:39d2c685af15d3ce682c99ce5925cc66e...
"sha256:56bc8ded6fcd9adea90f65377438f9fea...
"sha256:590355aeade1a2eaba17617c19edccb7d...
"sha256:70a840a26f4e61defa7bdf811d7498a28...
"sha256:77c3bfe65d8560487052ad55c6998a04b...
"sha256:9537eecf179f566fd1c160a2e912ca0b8...
"sha256:9acdf933c1fd263c513a2df3dceecea6f...
"sha256:ae0975f42ab1f28364dcda3dde3cf6c1d...
"sha256:b3af02ecc999c8003e538e60c89a2b376...
"sha256:b6ff59cee96b454516e47e7721098e6ce...
"sha256:b765ed3930b92812aa698a45584714186...
"sha256:c98c5ffd7d41611407a1103ae11c8b634...
"sha256:cf7eb6b1025d3e169989416b1adcd6766...
"sha256:d92350c22b150c1cae7ebb0ee8b5670cc...
"sha256:e422c3152921cece8b6a2fb6b0b4d73b6...
"sha256:e840f552a509e3380b0f0ec977e8124d0...
"sha256:f3d0a94ad151870978fb93538e95411c8...
],
"index": "pypi",
"version": "==1.18.1"
}
},
"develop": {
"autopep8": {
"hashes": [
"sha256:0f592a0447acea0c2b0a9602be1e4e3d8...
],
"index": "pypi",
"version": "==1.5"
},
"entrypoints": {
"hashes": [
"sha256:589f874b313739ad35be6e0cd7efde2a4...
"sha256:c70dd71abe5a8c85e55e12c19bd91ccfe...
],
"version": "==0.3"
},
"flake8": {
"hashes": [
"sha256:45681a117ecc81e870cbf1262835ae4af...
"sha256:49356e766643ad15072a789a20915d3c9...
],
"index": "pypi",
"version": "==3.7.9"
},
"mccabe": {
"hashes": [
"sha256:ab8a6258860da4b6677da4bd2fe5dc2c6...
"sha256:dd8d182285a0fe56bace7f45b5e7d1a6e...
],
"version": "==0.6.1"
},
"pycodestyle": {
"hashes": [
"sha256:95a2219d12372f05704562a14ec30bc76...
"sha256:e40a936c9a450ad81df37f549d676d127...
],
"version": "==2.5.0"
},
"pyflakes": {
"hashes": [
"sha256:17dbeb2e3f4d772725c777fabc446d563...
"sha256:d976835886f8c5b31d47970ed689944a0...
],
"version": "==2.1.1"
}
}
}
}}}
*pipenv プロジェクトの復元 [#m4f16ec2]
-開発環境に git でプロジェクトを clone して、依存ライブラ...
-Pipfile からライブラリをダウンロード (Pipfile.lock はそ...
$ pipenv install
$ pipenv install --dev
-Pipfile.lock に書いてあるバージョンをダウンロードする
$ pipenv sync
$ pipenv sync --dev
*pipenv 環境に入る [#za53af0f]
$ pipenv shell
Launching subshell in virtual environment…
(pySample) ~/python/pySample$ exit
$
*pipenv で python プログラムを実行する [#yf19335f]
-pySample/matrix.py に numpy を使ったサンプルを作る
#code(python){{{
import numpy as np
a = np.array([1, 2, 3, 4, 5])
b = np.array([6, 7, 8, 9, 10])
c = a + b
print(c)
}}}
-実行
$ pipenv run python3 pySample/matrix.py
[ 7 9 11 13 15]
*pipenv 環境で動くプログラムを登録する [#zd554233]
-Pipfile に [scripts] セクションを作って、pipenv 環境で動...
[scripts]
test = "python -m unittest discover -v"
format = "autopep8 -ivr ."
lint = "flake8 --show-source ."
-[scripts] セクションにあるプログラムは、pipenv run 経由...
$ pipenv run test
--------------------------------------------------------...
Ran 0 tests in 0.000s
OK
*pipenv でライブラリを作る [#q4271e85]
-ほかから使われるライブラリを作る場合には、引き続き setup...
--https://docs.python.org/ja/3/distutils/setupscript.html
-今作っているのが最終製品である場合には pipenv だけで OK
-今のところ (Jan 2020) 、pipenv と setup.py は連携しない...
*pipenv と vscode [#r6e07adb]
-python extension がインストールされていれば、pipenv 環境...
#ref(vscode.png)
----
[[Python]]
終了行:
#contents
*これは何? [#g2a5c01b]
-公式サイト: https://github.com/pypa/pipenv
-Pipenv = pip + pyenv
--pip : Python のライブラリを管理する機構
--pyenv : アプリケーション実行環境をアプリケーションごと...
-Java や Node にはもともと持っている機構
*インストール [#c5d26000]
$ python3 --version
Python 3.5.3
$ sudo apt install python3-pip
$ pip3 -V
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
$ pip3 install --user --upgrade pipenv
これで ~/.local/bin/pip/ に pipenv がインストールされて、...
最後に、PATH に ~/.local/bin を追加する (最初から入ってい...
- ~/.profile
#code(bash){{{
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin":$PATH
fi
}}}
$ source ~/.profile
$ pipenv --version
pipenv, version 2018.11.26
*pipenv プロジェクトの作成 [#n95f37b8]
-プロジェクトの初期化
$ mkdir pySample
$ cd pySample
$ mkdir pySample
$ mkdir docs
$ mkdir notes
$ mkdir tests
$ touch LICENSE
$ touch README.md
$ touch pySample/__init__.py
$ touch tests/__init__.py
$ pipenv --three
Creating a virtualenv for this project…
Pipfile: /home/atsushihondoh/python/pySample/Pipfile
Using /usr/bin/python3.5m (3.5.3) to create virtualenv…
...
-標準的なプロジェクト構成
$ tree
.
├── LICENSE
├── Pipfile
├── Pipfile.lock
├── README.md
├── docs
├── notes
├── pySample
│ └── __init__.py
└── tests
└── __init__.py
-依存関係は Pipfile に記載される
#code(python){{{
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
[requires]
python_version = "3.5"
}}}
-依存ライブラリの指定
$ pipenv install numpy
-開発用ライブラリの指定 (テストやコード整形のためのライブ...
$ pipenv install --dev autopep8 flake8
-Pipfile は次のようになります
#code(python){{{
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
autopep8 = "*"
flake8 = "*"
[packages]
numpy = "*"
[requires]
python_version = "3.5"
}}}
-より詳細な依存ライブラリの情報は Pipfile.lock に記述され...
#code(python){{{
{
"_meta": {
"hash": {
"sha256": "1c1d943573ca6420ef250bbdcbea2b850b...
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.5"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"numpy": {
"hashes": [
"sha256:1786a08236f2c92ae0e70423c45e1e627...
"sha256:17aa7a81fe7599a10f2b7d95856dc5cf8...
"sha256:20b26aaa5b3da029942cdcce719b363db...
"sha256:2d75908ab3ced4223ccba595b48e538af...
"sha256:39d2c685af15d3ce682c99ce5925cc66e...
"sha256:56bc8ded6fcd9adea90f65377438f9fea...
"sha256:590355aeade1a2eaba17617c19edccb7d...
"sha256:70a840a26f4e61defa7bdf811d7498a28...
"sha256:77c3bfe65d8560487052ad55c6998a04b...
"sha256:9537eecf179f566fd1c160a2e912ca0b8...
"sha256:9acdf933c1fd263c513a2df3dceecea6f...
"sha256:ae0975f42ab1f28364dcda3dde3cf6c1d...
"sha256:b3af02ecc999c8003e538e60c89a2b376...
"sha256:b6ff59cee96b454516e47e7721098e6ce...
"sha256:b765ed3930b92812aa698a45584714186...
"sha256:c98c5ffd7d41611407a1103ae11c8b634...
"sha256:cf7eb6b1025d3e169989416b1adcd6766...
"sha256:d92350c22b150c1cae7ebb0ee8b5670cc...
"sha256:e422c3152921cece8b6a2fb6b0b4d73b6...
"sha256:e840f552a509e3380b0f0ec977e8124d0...
"sha256:f3d0a94ad151870978fb93538e95411c8...
],
"index": "pypi",
"version": "==1.18.1"
}
},
"develop": {
"autopep8": {
"hashes": [
"sha256:0f592a0447acea0c2b0a9602be1e4e3d8...
],
"index": "pypi",
"version": "==1.5"
},
"entrypoints": {
"hashes": [
"sha256:589f874b313739ad35be6e0cd7efde2a4...
"sha256:c70dd71abe5a8c85e55e12c19bd91ccfe...
],
"version": "==0.3"
},
"flake8": {
"hashes": [
"sha256:45681a117ecc81e870cbf1262835ae4af...
"sha256:49356e766643ad15072a789a20915d3c9...
],
"index": "pypi",
"version": "==3.7.9"
},
"mccabe": {
"hashes": [
"sha256:ab8a6258860da4b6677da4bd2fe5dc2c6...
"sha256:dd8d182285a0fe56bace7f45b5e7d1a6e...
],
"version": "==0.6.1"
},
"pycodestyle": {
"hashes": [
"sha256:95a2219d12372f05704562a14ec30bc76...
"sha256:e40a936c9a450ad81df37f549d676d127...
],
"version": "==2.5.0"
},
"pyflakes": {
"hashes": [
"sha256:17dbeb2e3f4d772725c777fabc446d563...
"sha256:d976835886f8c5b31d47970ed689944a0...
],
"version": "==2.1.1"
}
}
}
}}}
*pipenv プロジェクトの復元 [#m4f16ec2]
-開発環境に git でプロジェクトを clone して、依存ライブラ...
-Pipfile からライブラリをダウンロード (Pipfile.lock はそ...
$ pipenv install
$ pipenv install --dev
-Pipfile.lock に書いてあるバージョンをダウンロードする
$ pipenv sync
$ pipenv sync --dev
*pipenv 環境に入る [#za53af0f]
$ pipenv shell
Launching subshell in virtual environment…
(pySample) ~/python/pySample$ exit
$
*pipenv で python プログラムを実行する [#yf19335f]
-pySample/matrix.py に numpy を使ったサンプルを作る
#code(python){{{
import numpy as np
a = np.array([1, 2, 3, 4, 5])
b = np.array([6, 7, 8, 9, 10])
c = a + b
print(c)
}}}
-実行
$ pipenv run python3 pySample/matrix.py
[ 7 9 11 13 15]
*pipenv 環境で動くプログラムを登録する [#zd554233]
-Pipfile に [scripts] セクションを作って、pipenv 環境で動...
[scripts]
test = "python -m unittest discover -v"
format = "autopep8 -ivr ."
lint = "flake8 --show-source ."
-[scripts] セクションにあるプログラムは、pipenv run 経由...
$ pipenv run test
--------------------------------------------------------...
Ran 0 tests in 0.000s
OK
*pipenv でライブラリを作る [#q4271e85]
-ほかから使われるライブラリを作る場合には、引き続き setup...
--https://docs.python.org/ja/3/distutils/setupscript.html
-今作っているのが最終製品である場合には pipenv だけで OK
-今のところ (Jan 2020) 、pipenv と setup.py は連携しない...
*pipenv と vscode [#r6e07adb]
-python extension がインストールされていれば、pipenv 環境...
#ref(vscode.png)
----
[[Python]]
ページ名:
ISBN10
ISBN13
9784061426061