# pipenv ###### tags:`NCKU_ES` `python lecture` 和別人一起開發專案的實用技巧 - 虛擬環境 >「做 Python Project 不用 Pipenv 會下地獄ㄛ!」 「控制該語言的使用版本」以及「控制使用的套件版本」如果大家用的版本都不一樣就天下大亂了! 本文主要摘錄自 [Citation](https://pipenv-fork.readthedocs.io/en/latest/basics.html) ## Installation ```bash= $ pip install pipenv ``` ## 創建特定版本的環境 ```bash= # pipenv --python [PYTHON VERSION] $ pipenv --python 3.7 ``` ### 安裝套件 ```bash= $ pipenv install requests numpy ``` 指定套件版本: ```bash= $ pipenv install requests~=1.2 ``` ### 解除安裝套件 ```bash= $ pipenv uninstall pytest $ pipenv install "requests>=1.4" # will install a version equal or larger than 1.4.0 $ pipenv install "requests<=2.13" # will install a version equal or lower than 2.13.0 $ pipenv install "requests>2.19" # will install 2.19.1 but not 2.19.0 ``` >The use of ~= is preferred over the == identifier as the latter prevents pipenv from updating the packages: ### 進入環境 ```bash= $ pipenv shell ``` ### 離開環境 ```bash= $ exit ``` ### 產生 requirements ```bash= $ pipenv lock --requirements > requirements.txt ``` ### Import from requirements 只要有 requirements.txt 執行 `pipenv install` 就會幫你建環境囉! >If you only have a requirements.txt file available when running `pipenv install` , pipenv will automatically import the contents of this file and create a Pipfile for you. 或是也可以這樣 ```bash= $ pipenv install -r path/to/requirements.txt ```