ãã®è¨äºã¯ 2017/9 ã«æ¸ããããã®ã§ããã2019/11/26 ç¾å¨ã¨ã¯ç¶æ³ãå¤ãã£ã¦ãã¾ããå ¬å¼ããã¥ã¡ã³ã(æ¥æ¬èªè¨³)ãåç §ãã¦ãã ããã
æ代㯠pipenv ã
— ããããããð°ð (@utgwkk) September 5, 2017
ãã誰ãï¼requirements.txt ãï¼source ENV/bin/activate
ã«é ãæ©ã¾ãããæ代ã¯çµãã£ãï¼
ã¨ãããã㧠virtualenv ã®æ代ã¯çµãã*1ï¼pipenv ã®æ代ã«ãªãã¾ããï¼
ãã®è¨äºã¯ Python ãæ¸ã人éãå ¨å¡ pipenv ã使ãã¹ãã ã¨ããæããè¾¼ãã¦æ¸ãã¾ããï¼æ¥æ¬èªã§æ¸ãããè¨äºãã¾ã ãããããªãã¨ããäºæ ãããã¾ãï¼
pipenv ã¨ã¯
Python ã®ããã±ã¼ã¸ç®¡çãã¼ã«ã® pip ã¨ï¼ç°å¢åãåããã¼ã«ã® virtualenv ãèåããããã¼ã«ã§ãï¼Ruby ã§ããã¨ããã® Bundler ãæ³åããã¨åãããããã¨æãã¾ã*2ï¼
Python Packaging User Guide ã§ã pipenv ãæ¨å¥¨ããã¦ãã¾ãï¼
ã¤ã³ã¹ãã¼ã«
ãã pip ã³ãã³ãããªããã° ensurepip ã試ãã¦ãã ããï¼
$ pip install pipenv
ç°å¢ãä½ã
ã«ã¬ã³ããã£ã¬ã¯ããªã« Python3 ã®ç°å¢ãä½ãã«ã¯ï¼
$ pipenv --three # Windows ã®å ´åã¯ä¸è¨ # pipenv --python <python.exe ã¸ã®ãã¹>
ãå®è¡ãã¾ã*3ï¼ ããã«ãã£ã¦ç°å¢ãä½ããï¼ã«ã¬ã³ããã£ã¬ã¯ããªã« Pipfile ãä½æããã¾ãï¼
ãµãã³ãã³ãä¸è¦§
pipenv check
Pipfile ã PEP 508 (Python ã®ä¾åããã±ã¼ã¸æå®ã®æ¸å¼) ã«å¾ã£ã¦ããã確èªãã¾ãï¼ å¤ãã®å ´åã¯æããªãã¦ãããã®ã§ã¯ãªãã§ããããï¼
pipenv install
ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ãï¼Pipfile ã«è¿½å ãã¾ãï¼
$ pipenv install (package-name)
ããã±ã¼ã¸åãæå®ããªãå ´åã¯ï¼Pipfile ã«è¨è¿°ããããã¡ dev-dependencies ãé¤ã ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ããã¾ãï¼
pipenv lock
Pipfile.lock (å¾è¿°) ãä½æãã¾ãï¼
pipenv run
ã«ã¬ã³ããã£ã¬ã¯ããªã® Python ã®ç°å¢ã§ã³ãã³ããå©ããã¨ãã§ãã¾ãï¼Bundler ã§è¨ãã¨ããã® bundle exec
ã§ãï¼
ãã¨ãã°ãã®ãã£ã¬ã¯ããªã®ç°å¢ã§ main.py
ãå®è¡ãããå ´åã¯ï¼ãã®ããã«ï¼
$ pipenv run python main.py
ãã activate ãã¦ããã³ãã³ããå©ãå¿
è¦ã¯ããã¾ããï¼ã°ãã¼ãã«ç°å¢ã« pipenv ãã¤ã³ã¹ãã¼ã«ããã¦ããï¼ãã¤äºåã« pipenv install
ãæ¸ã¾ãã¦ããããã°ããã®ã§ãï¼
ããã使ãããã ãã« pipenv ãå
¥ããã¨ãã£ã¦ãéè¨ã§ã¯ããã¾ããï¼
pipenv shell
ãã£ã±ãã¾ã virtualenv ã使ãããï¼activate ãããã¨ãã人ã®ããã®ã³ãã³ãã§ãï¼è¦ããã« source ENV/bin/activate
ããã¾ãï¼
å½æ¹ã®ç°å¢ã§ã¯ããã³ããã®è¡¨ç¤ºã¯å¤ããã¾ããã§ãããï¼æ®éã« exit
ãªã©ã§æãåºããã¨ãã§ãã¾ãï¼
pipenv uninstall
ããã±ã¼ã¸ãã¢ã³ã¤ã³ã¹ãã¼ã«ãï¼Pipfile ããåé¤ãã¾ãï¼
pipenv update
pip ãææ°çã«ã¢ãããã¼ããï¼ç°å¢ãä½æããªããã¾ãï¼
pipenv ã®ãããã
dev-packages ã«ã¤ãã¦
éçºã®ã¿ã«ä½¿ãï¼ãããã¤æã«ã¯ä½¿ããªãä¾åããã±ã¼ã¸ã§ãï¼ãã¹ãç¨ã©ã¤ãã©ãªã¨ãï¼ ããã¾ã§ã¯ requirements-dev.txt ã®ãããªãã¡ã¤ã«ã«åããã¦ãããã®ã1ãã¡ã¤ã«ã§æ¸ãããã«ãªãã¾ããï¼
$ pipenv install -d
㧠dev-packages ãå«ããå ¨ã¦ã®ä¾åã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«ã§ãã¾ãï¼
Pipfile ã«ã¤ãã¦
ããã±ã¼ã¸ã®ä¾åé¢ä¿ãªã©ã TOML ã§è¨è¿°ããã¦ãããã¡ã¤ã«ã§ãï¼ èªåã§æ¸ãæãããã¦ããã®ã§ãããªã«è§¦ããã¨ã¯ãªããã(ã»ãã¨ããï¼)ï¼
Pipfile.lock ã«ã¤ãã¦
$ pipenv lock
ãå©ããã¨ã§çæããããã¡ã¤ã«ã§ãï¼Gemfile.lock ã¨ããããåãå½¹å²ãæããã¦ãã¾ãï¼
ç°å¢ã¯ã©ãã«ä¿åããã¦ããã®ï¼
$ pipenv --venv
ã§ç¢ºèªãããã¨ãã§ãã¾ãï¼~/.local/share/virtualenvs/
以ä¸ã«é©å½ãªãã£ã¬ã¯ããªãä½æããï¼ããã«ä¿åããã¦ãã¾ãï¼
Bundler ã¿ãããã£ã¬ã¯ããªãæå®ãããã¨ã¯ã§ããªãããã§ãï¼
ä½æãããç°å¢ã® Python ã®ãã¼ã¸ã§ã³ã¯ï¼
pipenv ãã¤ã³ã¹ãã¼ã«ãã Python ã®ãã¼ã¸ã§ã³ã«ä¾åãã¾ãï¼
pipenv --three
ãã§ããã®ã¯ Python3 系㫠pipenv ãã¤ã³ã¹ãã¼ã«ããã¨ãã ãã§ãï¼
ã¾ãä»æ Python2 ãã使ããªããããªä¸å¹¸ãªç°å¢ã¨ããã®ã¯ãããããªãã¨æãè¾¼ãã§ãã¾ããâ¦â¦ï¼
ã¾ã¨ã
ãã誰ãï¼requirements.txt ãï¼source ENV/bin/activate
ã«é ãæ©ã¾ãããæ代ã¯çµãã£ãï¼(åæ²)
ã¨ããããã§ï¼ç°å¢åãåãã®ããã«2ã¤ã®ã³ãã³ããé§ä½¿ããæ代ã¯çµããã¾ããï¼
ã©ãã©ã pipenv ã使ã£ã¦ããã¾ãããï¼
*1:追è¨: virtualenv èªä½ã¯ã¾ã çµãã£ã¦ãããï¼pipenv ã®å é¨ã§ç¨ãããã¦ãã¾ã
*2:ã¨è¨ã£ããã©ï¼pip 㨠virtualenv ããã£ã¨å¿«é©ã«æ±ãããã®ã©ããã¨ãã¦ã®æ©è½ãå¼·ãã¨æã
*3:ä½è«ã§ããï¼ãããããªãã§åæã« pipenv install ãå®è¡ãã¦ãç°å¢ã¯ä½ããã¾ã