python virtual environment Pipenv

Prerequisite environment

Pipenv

Installation

D:\work> pip install pipenv
Collecting pipenv
  Using cached pipenv-2020.8.13-py2.py3-none-any.whl (3.9 MB)
Requirement already satisfied: pip>=18.0 in c:\users\username\appdata\local\programs\python\python38\lib\site-packages (from pipenv) (20.2.3)
Requirement already satisfied: certifi in c:\users\username\appdata\local\programs\python\python38\lib\site-packages (from pipenv) (2020.6.20)
Requirement already satisfied: setuptools>=36.2.1 in c:\users\username\appdata\local\programs\python\python38\lib\site-packages (from pipenv) (41.2.0)
Requirement already satisfied: virtualenv in c:\users\username\appdata\local\programs\python\python38\lib\site-packages (from pipenv) (20.0.33)
Requirement already satisfied: virtualenv-clone>=0.2.5 in c:\users\username\appdata\local\programs\python\python38\lib\site-packages (from pipenv) (0.5.4)
Requirement already satisfied: filelock<4,>=3.0.0 in c:\users\username\appdata\local\programs\python\python38\lib\site-packages (from virtualenv->pipenv) (3.0.12)
Requirement already satisfied: distlib<1,>=0.3.1 in c:\users\username\appdata\local\programs\python\python38\lib\site-packages (from virtualenv->pipenv) (0.3.1)
Requirement already satisfied: appdirs<2,>=1.4.3 in c:\users\username\appdata\local\programs\python\python38\lib\site-packages (from virtualenv->pipenv) (1.4.4)
Requirement already satisfied: six<2,>=1.9.0 in c:\users\username\appdata\local\programs\python\python38\lib\site-packages (from virtualenv->pipenv) (1.15.0)
Installing collected packages: pipenv
Successfully installed pipenv-2020.8.13

Installation confirmation

D:\work> pipenv
Usage: pipenv [OPTIONS] COMMAND [ARGS]...

Options:
  --where                         Output project home information.
  --venv                          Output virtualenv information.
  --py                            Output Python interpreter information.
  --envs                          Output Environment Variable options.
  --rm                            Remove the virtualenv.
  --bare                          Minimal output.
  --completion                    Output completion (to be executed by the
                                  shell).

  --man                           Display manpage.
  --support                       Output diagnostic information for use in
                                  GitHub issues.

  --site-packages / --no-site-packages
                                  Enable site-packages for the virtualenv.
                                  [env var: PIPENV_SITE_PACKAGES]

  --python TEXT                   Specify which version of Python virtualenv
                                  should use.

  --three / --two                 Use Python 3/2 when creating virtualenv.
  --clear                         Clears caches (pipenv, pip, and pip-tools).
                                  [env var: PIPENV_CLEAR]

  -v, --verbose                   Verbose mode.
  --pypi-mirror TEXT              Specify a PyPI mirror.
  --version                       Show the version and exit.
  -h, --help                      Show this message and exit.


Usage Examples:
   Create a new project using Python 3.7, specifically:
   $ pipenv --python 3.7

   Remove project virtualenv (inferred from current directory):
   $ pipenv --rm

   Install all dependencies for a project (including dev):
   $ pipenv install --dev

   Create a lockfile containing pre-releases:
   $ pipenv lock --pre

   Show a graph of your installed dependencies:
   $ pipenv graph

   Check your installed dependencies for security vulnerabilities:
   $ pipenv check

   Install a local setup.py into your virtual environment/Pipfile:
   $ pipenv install -e .

   Use a lower-level pip command:
   $ pipenv run pip freeze

Commands:
  check      Checks for PyUp Safety security vulnerabilities and against PEP
             508 markers provided in Pipfile.

  clean      Uninstalls all packages not specified in Pipfile.lock.
  graph      Displays currently-installed dependency graph information.
  install    Installs provided packages and adds them to Pipfile, or (if no
             packages are given), installs all packages from Pipfile.

  lock       Generates Pipfile.lock.
  open       View a given module in your editor.
  run        Spawns a command installed into the virtualenv.
  shell      Spawns a shell within the virtualenv.
  sync       Installs all packages specified in Pipfile.lock.
  uninstall  Uninstalls a provided package and removes it from Pipfile.
  update     Runs lock, then sync.

Create virtual environment

Prepare a folder for the virtual environment

D:\work> mkdir mytestenv


directory: D:\work


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2020/10/07     18:55                mytestenv

Create virtual environment

D:\work> cd mytestenv
D:\work\mytestenv> pipenv install
Creating a virtualenv for this project…
Pipfile: D:\work\mytestenv\Pipfile
Using C:/Users/username/AppData/Local/Programs/Python/Python38/python.exe (3.8.2) to create virtualenv…
[=== ] Creating virtual environment...created virtual environment CPython3.8.2.final.0-64 in 4929ms
  creator CPython3Windows(dest=C:\Users\username\.virtualenvs\mytestenv-1lNwFUaT, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\username\AppData\Local\pypa\virtualenv)
    added seed packages: pip==20.2.3, setuptools==50.3.0, wheel==0.35.1
  activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

Successfully created virtual environment!
Virtualenv location: C:\Users\username\.virtualenvs\mytestenv-1lNwFUaT
Creating a Pipfile for this project…
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (db4242)!
Installing dependencies from Pipfile.lock (db4242)…
  ================================ 0/0 - 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

Switch to virtual environment

PS D:\work\mytestenv> pipenv shell

Switched state


Launching subshell in virtual environment…
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6
PS D:\work\mytestenv> 

Add library to try


D:\work\mytestenv> pip list
Package    Version
---------- -------
pip        20.2.3
setuptools 50.3.0
wheel      0.35.1

D:\work\mytestenv> pip install numpy
Collecting numpy
  Using cached numpy-1.19.2-cp38-cp38-win_amd64.whl (13.0 MB)
Installing collected packages: numpy
Successfully installed numpy-1.19.2

D:\work\mytestenv> pip list
Package    Version
---------- -------
numpy      1.19.2
pip        20.2.3
setuptools 50.3.0
wheel      0.35.1

Return from virtual environment


D:\work\mytestenv>exit ・ ・ ・ You can go back with this
D:\work\mytestenv>pip list ・ ・ ・ Check if you really returned
Package                          Version
-------------------------------- ---------
appdirs                          1.4.4
asgiref                          3.2.7
blinker                          1.4
(abridgement)

end

The python version switch still looks like you have to install another version of python on your machine, so next time.

python version specification

It seems to do this.

pipenv --python 3.6
pipenv --python 2.7.14

Recommended Posts

python virtual environment Pipenv
virtual environment in python
Virtual environment with Python 3.6
Building a Python virtual environment
venv: Python virtual environment management
python standard virtual environment venv
Building a Python virtual environment
Build python virtual environment with virtualenv
[Personal memo] Python virtual environment command memo
Create a virtual environment with Python!
Building a virtual environment with Python 3
pytorch @ python3.8 environment construction with pipenv
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Python environment construction
python environment settings
python windows environment
Environment construction (python)
Beginner virtual environment
python environment construction
Python --Environment construction
Python environment construction
python environment construction
Install Django in a pipenv virtual environment
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
Python virtual environment and packages on Ubuntu
Let's create a virtual environment for Python
[Python] Create a virtual environment with Anaconda
[Mac] Building a virtual environment for Python
Creating a python virtual environment on Windows
Build a python virtual environment with pyenv
Add a Python virtual environment to VSCode
[Understanding in the figure] Management of Python virtual environment by Pipenv
[Python] Get environment variables
My python environment memo
How to create a Python virtual environment (venv)
Ubuntu18.04.05 Creating a python virtual environment in LTS
Unification of Python environment
python windows environment construction
homebrew python environment construction
Start Django in a virtual environment with Pipenv
Create a virtual environment with conda in Python
About Python development environment
[Python] Web development preparation (building a virtual environment)
Build a simple Python virtual environment without pyenv
[Venv] Create a python virtual environment on Ubuntu
Python environment with docker-compose
[Node-RED] Execute Python on Anaconda virtual environment from Node-RED [Anaconda] [Python]
Work in a virtual environment with Python virtualenv.
python2.7 development environment construction
Use jupyter-lab installed in python virtual environment (venv)
Create a Python environment
Development environment in Python
Mac environment construction Python
PyTorch introduction (virtual environment)
From Python environment construction to virtual environment construction with anaconda
Create a Python virtual development environment on Windows
Python environment construction @ Win7
Python environment for projects
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Python: Creating a virtual environment (venv), starting and stopping
Build a python virtual environment with virtualenv and virtualenvwrapper