create account

[Python Tips] Are you still using Pip? by themarkymark

View this thread on: hive.blogpeakd.comecency.com
· @themarkymark ·
$44.86
[Python Tips] Are you still using Pip?
![](https://steemitimages.com/DQmSsFP8BDE1DkXNN9hh1729MRexyqupLEKfWJTsRskjt33/image.png) 

In a [previous tip](https://peakd.com/programming/@themarkymark/python-tips-virtual-environments) I talked about Virtual Environments and why you should be using them.  While there are a few ways to do them, I want to talk more in-depth about my favorite.

# Introducing pipenv

Pipenv is like a combination of **Pip, VirtualEnv, and NPM** although technically it's a combination of **Pip** & **VirtualEnv**.

PipEnv brings package.json type of functionality with the file Pipfile.

Pip makes it super easy to create virtual environments, switching to virtual environments, and running under a virtual environment without switching.  It also manages your dependencies and gives you an easy way to look at your dependency graph.

Before you can use pipenv, you need to install it.

# Pipenv installation

Pipenv is available on PyPi, so all you have to do is:

`pip install -U pipenv`

I recommend keeping pipenv global, so installing it directly is ideal.

---

# Using pipenv

You can use pipenv similar to how you would use NPM to install packages and update the package file (in this case Pipfile).

One of the biggest features that most people don't even know about (I'm guessing they don't) is the additional security pipenv brings.  Pipenv uses hashes everywhere and checks the file hashes for all locked dependencies.

Unlike VirtualEnv, pipenv does not create copies of modules and packages in your working folder.  

Beem installed w/ VirtualEnv

https://i.imgur.com/StD0XCx.png

Beem installed w/ Pipenv

https://i.imgur.com/YhRnTHa.png

Pipenv allows you to easily specify Python 2 or Python 3 when creating an environment.

Pipenv has two main commands for running your applications.

**shell** - To enter your environment
**run** - To run code without entering environment first

I'm not going to get into creating a Pipfile manually, Pipenv does a good job managing it automatically.  There are some cases you might want to edit it by hand but that's beyond the scope of this tutorial.

#### Creating a virtual environment with pipenv

I'm going to skip this, because all you need to do is install a module and pipenv will start creating an environment for you.

---

#### Installing modules with Pipenv

Just like pip, all you do is 

`pipenv install <module>`

If there is not a Pipfile, it will create one and start a new environment.  

You can uninstall packages using `pipenv uninstall`.

You can use a requirements.txt file to load your dependencies similar to pip by using `pipenv install -r requirements.txt`.

You can then use `pip install` to install all packages from the Pipfile when you are ready to deploy are installing on a new machine.

---

#### Switching to your environment

Once you installed your packages, you can switch to your new virtual environment by using:

`pipenv shell`

This will enter the virtual environment, much like you do with VirtualEnv.

You can skip that all together and just run `pipenv run python mycode.py arguments` to just execute your code without switching first.

---

#### Updating Modules

You can easily upgrade modules by running `pipenv update`, pipenv will make the necessary changes to the Pipfile and Pipfile.lock for you.

---

#### Dev Packages

Like NPM, and unlike pip, you can install packages for development only.  These are packages you need to do development (like linting software) but for the final deployment, they are not needed.

All you do is add --dev to the install command.

`pipenv install --dev pylint`

You can install all packages including dev packages using `pip install --dev`.

---

#### Dependency Graph

Pipenv has a really cool feature to look over the dependency graph of your application.  

Just type `pip graph` and you will see something like this:

```
hivepy==0.9.999
  - appdirs [required: Any, installed: 1.4.4]
  - certifi [required: Any, installed: 2020.4.5.2]
  - ecdsa [required: >=0.13, installed: 0.15]
    - six [required: >=1.9.0, installed: 1.15.0]
  - funcy [required: Any, installed: 1.14]
  - future [required: Any, installed: 0.18.2]
  - langdetect [required: Any, installed: 1.0.8]
    - six [required: Any, installed: 1.15.0]
  - prettytable [required: Any, installed: 0.7.2]
  - pycrypto [required: >=1.9.1, installed: 2.6.1]
  - pylibscrypt [required: >=1.6.1, installed: 1.8.0]
  - scrypt [required: >=0.8.0, installed: 0.8.15]
  - toolz [required: Any, installed: 0.10.0]
  - ujson [required: Any, installed: 3.0.0]
  - urllib3 [required: Any, installed: 1.25.9]
  - voluptuous [required: Any, installed: 0.11.7]
  - w3lib [required: Any, installed: 1.22.0]
    - six [required: >=1.4.1, installed: 1.15.0]
PyYAML==5.3.1
requests==2.23.0
  - certifi [required: >=2017.4.17, installed: 2020.4.5.2]
  - chardet [required: >=3.0.2,<4, installed: 3.0.4]
  - idna [required: >=2.5,<3, installed: 2.9]
  - urllib3 [required: >=1.21.1,<1.26,!=1.25.1,!=1.25.0, installed: 1.25.9]
```

Really handy if you want an overview of your dependencies.

---

There are more features I suggest you check out if you have more questions.  A good resource for pipenv can be found [here](https://pipenv.pypa.io/en/latest/).

**If you are using Git, it is recommended to check in both Pipfile & Pipfile.lock.**

As you can see, Pip & VirtualEnv are no match for Pipenv.

I have written a lot of Python tutorials, check them out!

---

# My Python Tips Series

* [f-strings in Python 3.6](https://peakd.com/programming/@themarkymark/python-tips-f-strings-in-python-3-6-and-why-you-should-be-using-them)
* [Underscores in numeric literals](https://peakd.com/programming/@themarkymark/python-tips-underscores-in-numeric-literals)
* [A better interactive shell](https://peakd.com/programming/@themarkymark/python-tips-a-better-interactive-shell)
* [Secrets Module - New in 3.6](https://peakd.com/programming/@themarkymark/python-tips-secrets-module-new-in-3-6)
* [PEP 8](https://peakd.com/programming/@themarkymark/python-tips-pep-8)
* [Slices](https://peakd.com/programming/@themarkymark/python-tips-slices)
* [Named Tuples](https://peakd.com/programming/@themarkymark/python-tips-named-tuples)
* [Destructuring](https://peakd.com/programming/@themarkymark/python-tips-destructuring)
* [Counter](https://peakd.com/programming/@themarkymark/python-tips-counter)
* [Type Annotation](https://peakd.com/programming/@themarkymark/python-tips-type-annotation)
* [Jupyter Notebooks](https://peakd.com/programming/@themarkymark/python-tips-jupyter-notebooks)
* [Getting Help](https://busy.org/@themarkymark/python-tips-getting-help)
* [Virtual Environments](https://peakd.com/programming/@themarkymark/python-tips-virtual-environments)
* [Expiring Dict](https://peakd.com/programming/@themarkymark/python-tips-expiring-dict)
* [DRY Programming](https://peakd.com/programming/@themarkymark/python-tips-dry-programming)
* [Knowing what exists](https://peakd.com/programming/@themarkymark/python-tips-knowing-what-exists)
* [Apscheduler](https://peakd.com/utopian-io/@themarkymark/python-tips-apscheduler)
* [Caching data with CacheTools](https://peakd.com/development/@themarkymark/python-tips-caching-data-with-cachetools)
* [Walrus Operator](https://peakd.com/development/@themarkymark/python-tips-the-new-walrus-operator)
* [Requests](https://peakd.com/development/@themarkymark/python-tips-requests)
* [Easy Serialization with Pickle](https://peakd.com/hive-163521/@themarkymark/python-tips-easy-serialization-with-pickle)

---

<center>Securely chat with me on [Keybase](https://keybase.io/officialmarky)
<center>https://steemitimages.com/DQmcWxV1dpA1eAtw2ipwZiWZkydyVNU5LaLa2Ak1GUnbGmS/The-Marky-Mark.png </center>
# <center>  [Why you should vote me as witness](https://peakd.com/witness-category/@themarkymark/why-you-should-vote-for-themarkymark-as-witness)  </center> #
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 262 others
👎  , , , , , , , , , , , , , ,
properties (23)
authorthemarkymark
permlinkpython-tips-are-you-still-using-pip
categorypython-tips
json_metadata"{"app":"peakd/2020.05.5","format":"markdown","description":"Introducing pipenv","tags":["python-tips","python","development","dev","technology","palnet","neoxian","tutorial"],"users":["themarkymark"],"links":["/programming/@themarkymark/python-tips-virtual-environments","https://pipenv.pypa.io/en/latest/","/programming/@themarkymark/python-tips-f-strings-in-python-3-6-and-why-you-should-be-using-them","/programming/@themarkymark/python-tips-underscores-in-numeric-literals","/programming/@themarkymark/python-tips-a-better-interactive-shell","/programming/@themarkymark/python-tips-secrets-module-new-in-3-6","/programming/@themarkymark/python-tips-pep-8","/programming/@themarkymark/python-tips-slices","/programming/@themarkymark/python-tips-named-tuples","/programming/@themarkymark/python-tips-destructuring"],"image":["https://steemitimages.com/DQmSsFP8BDE1DkXNN9hh1729MRexyqupLEKfWJTsRskjt33/image.png","https://i.imgur.com/StD0XCx.png","https://i.imgur.com/YhRnTHa.png","https://steemitimages.com/DQmcWxV1dpA1eAtw2ipwZiWZkydyVNU5LaLa2Ak1GUnbGmS/The-Marky-Mark.png"]}"
created2020-06-11 04:49:33
last_update2020-06-11 04:49:33
depth0
children9
last_payout2020-06-18 04:49:33
cashout_time1969-12-31 23:59:59
total_payout_value24.962 HBD
curator_payout_value19.903 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7,866
author_reputation1,775,287,450,290,407
root_title"[Python Tips] Are you still using Pip?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,894,711
net_rshares98,625,512,241,711
author_curate_reward""
vote details (341)
@chitty ·
I have picked your post for my daily hive voting initiative, Keep it up and Hive On!!
properties (22)
authorchitty
permlinkre-python-tips-are-you-still-using-pip-20200612t000530
categorypython-tips
json_metadata""
created2020-06-12 00:05:33
last_update2020-06-12 00:05:33
depth1
children0
last_payout2020-06-19 00:05:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length86
author_reputation86,901,300,608,582
root_title"[Python Tips] Are you still using Pip?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,911,247
net_rshares0
@dhimmel ·
I've been using Pipenv for several months, but there was a long hiatus in their releases, leading [many to think](https://medium.com/telnyx-engineering/rip-pipenv-tried-too-hard-do-what-you-need-with-pip-tools-d500edc161d4) the project was dead.

[Releases](https://github.com/pypa/pipenv/releases) have recently resumed. In the meantime, it seems that poetry might [have surpassed](https://johnfraney.ca/posts/2019/11/19/pipenv-poetry-benchmarks-ergonomics-2/) Pipenv in features and design.

@themarkymark, have you tried https://python-poetry.org/? I'm looking forward to trying it for my next Python project.
👍  
properties (23)
authordhimmel
permlinkre-themarkymark-qbto9i
categorypython-tips
json_metadata{"tags":["python-tips"],"app":"peakd/2020.05.5"}
created2020-06-12 16:53:42
last_update2020-06-12 16:53:42
depth1
children1
last_payout2020-06-19 16:53:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length612
author_reputation39,788,295,023,882
root_title"[Python Tips] Are you still using Pip?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,924,552
net_rshares1,213,704,869
author_curate_reward""
vote details (1)
@themarkymark ·
$1.20
No I haven't but I think I heard of it then forgot to actually try it.  I will check it out but I really love pipenv.  I love how npm works and pipenv gives very similar functionality but better in some ways (no 3500 module node_modules folder). 

Python has always been more clunky with virtual environments. 
👍  ,
👎  , , , , , , , , , , , , ,
properties (23)
authorthemarkymark
permlinkre-dhimmel-qbtoja
categorypython-tips
json_metadata{"tags":["python-tips"],"app":"peakd/2020.05.5"}
created2020-06-12 16:59:33
last_update2020-06-12 16:59:33
depth2
children0
last_payout2020-06-19 16:59:33
cashout_time1969-12-31 23:59:59
total_payout_value0.600 HBD
curator_payout_value0.601 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length310
author_reputation1,775,287,450,290,407
root_title"[Python Tips] Are you still using Pip?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,924,647
net_rshares3,506,995,850,415
author_curate_reward""
vote details (16)
@joepferguson ·
Pipenv is great. At my day job we've started using pip-compile: https://github.com/jazzband/pip-tools and it's been working really well for us. 

Coming from the PHP community we have fantastic tools like https://getcomposer.org which is similar to what you'd find with NPM with a file you define dependencies (`package.json`, `composer.json`) and another file locking the versions to what has been installed (`package-lock.json`, `composer.lock`). It seemed silly to me that in Python dependency management is still seeing a lot of tooling changes and iteration but it seems headed in the right direction.
properties (22)
authorjoepferguson
permlinkre-themarkymark-qbtqwq
categorypython-tips
json_metadata{"tags":["python-tips"],"app":"peakd/2020.05.5"}
created2020-06-12 17:50:54
last_update2020-06-12 17:50:54
depth1
children0
last_payout2020-06-19 17:50:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length606
author_reputation311,169,878,614
root_title"[Python Tips] Are you still using Pip?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,925,452
net_rshares0
@katerinaramm ·
Hey @themarkymark I hope you are doing great :)
I would like to ask you if you could point me to the latest tutorial for the KeyChain, because I found 2 yesterday and I am not sure if there is another one, more recent.
Sorry to put you to trouble ...
Thanks in advance!
properties (22)
authorkaterinaramm
permlinkqbsv21
categorypython-tips
json_metadata{"users":["themarkymark"],"app":"hiveblog/0.1"}
created2020-06-12 06:22:54
last_update2020-06-12 06:22:54
depth1
children3
last_payout2020-06-19 06:22:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length269
author_reputation681,749,763,432,302
root_title"[Python Tips] Are you still using Pip?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,915,661
net_rshares0
@themarkymark ·
I don't have an up to date tutorial, but it is really easy.

Look in the extension store for Hive Keychain, make sure it is the one from @yabapmatt and install it.

https://i.imgur.com/0cvSyDu.png

Once installed, it will prompt you to set a password, you will need this to unlock the extension.  From there you can add your account(s) and it will manage authenticating to Hive services for you.

I do recommend setting the idle lock-in the preferences to lock the extension when you are not using it.  It tends to lock even when you are using it though after a set time.

If you still have questions, let me know and I can make a newer tutorial.
properties (22)
authorthemarkymark
permlinkre-katerinaramm-qbsvvl
categorypython-tips
json_metadata{"tags":["python-tips"],"app":"peakd/2020.05.5"}
created2020-06-12 06:40:30
last_update2020-06-12 06:40:30
depth2
children2
last_payout2020-06-19 06:40:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length647
author_reputation1,775,287,450,290,407
root_title"[Python Tips] Are you still using Pip?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,915,843
net_rshares0
@katerinaramm ·
Thanks so much, this is extra helpful and I feel really silly for not checking on github first before asking you :) 
I appreciate your time!
properties (22)
authorkaterinaramm
permlinkqbsw2f
categorypython-tips
json_metadata{"app":"hiveblog/0.1"}
created2020-06-12 06:44:45
last_update2020-06-12 06:44:45
depth3
children1
last_payout2020-06-19 06:44:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length140
author_reputation681,749,763,432,302
root_title"[Python Tips] Are you still using Pip?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,915,882
net_rshares0
@rafaelaquino · (edited)
Thank you for sharing this way of making virtual environments (pipenv). Very well explained and now I will practice it. The two ways you knew are: 
a) virtualenv python-exercise
b) python -m venv python-exercise 

Every day I learn more about python, this time thanks to you @themarkymark
properties (22)
authorrafaelaquino
permlinkqbrg0v
categorypython-tips
json_metadata{"users":["themarkymark"],"app":"hiveblog/0.1"}
created2020-06-11 12:00:33
last_update2020-06-11 12:08:24
depth1
children0
last_payout2020-06-18 12:00:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length288
author_reputation110,423,639,605,208
root_title"[Python Tips] Are you still using Pip?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id97,899,522
net_rshares0