Skip to content

Commit 3c99b32

Browse files
committed
Add pipenv Virtual Environment
1 parent 90bed71 commit 3c99b32

2 files changed

Lines changed: 82 additions & 48 deletions

File tree

‎README.md‎

Lines changed: 82 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ Example:
190190
- [Logging Levels](#logging-levels)
191191
- [Disabling Logging](#disabling-logging)
192192
- [Logging to a File](#logging-to-a-file)
193-
- [Virtual Environment](#virtual-environment)
194-
- [Windows](#windows)
195193
- [Lambda Functions](#lambda-functions)
196194
- [Ternary Conditional Operator](#ternary-conditional-operator)
195+
- [Virtual Environment](#virtual-environment)
196+
- [virtualenv](#virtualenv)
197+
- [pipenv](#pipenv)
197198

198199
## Python Basics
199200

@@ -3987,52 +3988,6 @@ logging.basicConfig(filename='myProgramLog.txt', level=logging.DEBUG, format='%(
39873988

39883989
[*Return to the Top*](#python-cheatsheet)
39893990

3990-
## Virtual Environment
3991-
3992-
The use of a Virtual Environment is to test python code in encapsulated environments and to also avoid filling the base Python installation with libraries we might use for only one project.
3993-
3994-
[*Return to the Top*](#python-cheatsheet)
3995-
3996-
### Windows
3997-
3998-
1. Install virtualenv:
3999-
4000-
pip install virtualenv
4001-
4002-
1. Install virtualenvwrapper-win:
4003-
4004-
pip install virtualenvwrapper-win
4005-
4006-
Usage:
4007-
4008-
1. Make a Virtual Environemt:
4009-
4010-
mkvirtualenv HelloWold
4011-
4012-
Anything we install now will be specific to this project. And available to the projects we connect to this environment.
4013-
4014-
1. Set Project Directory:
4015-
4016-
To bind our virtualenv with our current working directory we simply enter:
4017-
4018-
setprojectdir .
4019-
4020-
1. Deactivate:
4021-
4022-
To move onto something else in the command line type ‘deactivate’ to deactivate your environment.
4023-
4024-
deactivate
4025-
4026-
Notice how the parenthesis disappear.
4027-
4028-
1. Workon:
4029-
4030-
Open up the command prompt and type ‘workon HelloWold’ to activate the environment and move into your root project folder:
4031-
4032-
workon HelloWold
4033-
4034-
[*Return to the Top*](#python-cheatsheet)
4035-
40363991
## Lambda Functions
40373992

40383993
This function:
@@ -4116,3 +4071,82 @@ else:
41164071
```
41174072

41184073
[*Return to the Top*](#python-cheatsheet)
4074+
4075+
## Virtual Environment
4076+
4077+
The use of a Virtual Environment is to test python code in encapsulated environments and to also avoid filling the base Python installation with libraries we might use for only one project.
4078+
4079+
[*Return to the Top*](#python-cheatsheet)
4080+
4081+
### virtualenv
4082+
4083+
1. Install virtualenv
4084+
4085+
pip install virtualenv
4086+
4087+
1. Install virtualenvwrapper-win (Windows)
4088+
4089+
pip install virtualenvwrapper-win
4090+
4091+
Usage:
4092+
4093+
1. Make a Virtual Environment
4094+
4095+
mkvirtualenv HelloWold
4096+
4097+
Anything we install now will be specific to this project. And available to the projects we connect to this environment.
4098+
4099+
1. Set Project Directory
4100+
4101+
To bind our virtualenv with our current working directory we simply enter:
4102+
4103+
setprojectdir .
4104+
4105+
1. Deactivate
4106+
4107+
To move onto something else in the command line type ‘deactivate’ to deactivate your environment.
4108+
4109+
deactivate
4110+
4111+
Notice how the parenthesis disappear.
4112+
4113+
1. Workon
4114+
4115+
Open up the command prompt and type ‘workon HelloWold’ to activate the environment and move into your root project folder
4116+
4117+
workon HelloWold
4118+
4119+
[*Return to the Top*](#python-cheatsheet)
4120+
4121+
### pipenv
4122+
4123+
> Pipenv — the officially recommended Python packaging tool from Python.org, free (as in freedom).
4124+
4125+
1. Install pipenv
4126+
4127+
pip install pipenv
4128+
4129+
1. Enter your Project directory and install the Packages for your project
4130+
4131+
cd my_project
4132+
pipenv install <package>
4133+
4134+
Anything we install now will be specific to this project.
4135+
4136+
Pipenv will install your package and create a Pipfile for you in your project’s directory. The Pipfile is used to track which dependencies your project needs in case you need to re-install them.
4137+
4138+
1. Uninstall Packages
4139+
4140+
pipenv uninstall <package>
4141+
4142+
1. Activate the Virtual Environment associated with your Python project
4143+
4144+
pipenv shell
4145+
4146+
1. Exit the Virtual Environment
4147+
4148+
exit
4149+
4150+
Find more information and a video in [docs.pipenv.org](https://docs.pipenv.org/).
4151+
4152+
[*Return to the Top*](#python-cheatsheet)

‎python_cheat_sheet.pdf‎

17.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)