Take a “pip” into my programming toolbox
Dependency management in Python will have any programmer spoilt for choice and in this post I will be talking about some awesome tools that I use to get and stay productive.
Virtualenv is a tool used to create isolated Python installations. This means you can have Python 2.7 and Python 3.6 installed on a single system without any issues. Its very simple to get started with it:
virtualenv [name of virtual environment]
virtualenv venv - this creates a virtual environment named "venv"
source venv/bin/activate - this activates the virtual environment
and in an active environment you can now run pip install "package" to install any python package in that active environment.
deactivate - this deactivates the virtual environment
A “requirements file” is a file within a Python projects that contains a list of installed packages within a virtual environment. Its role is to communicate application dependencies to:
- Machines (build and deployment environments)
- People (developers, operations teams)
Normally with pip you can generate a requirements.txt file with this:
pip freeze > requirements.txt
on inspecting the file you will notice that the output isnt human friendly i.e. it contains some not so important information that a programmer might not need to know about. A sample output of the above command might look like this:
Hence pipreqs. It is a tool that generates a “requirements.txt” file based on explicit imports within a Python application. Running this command:
These are packages explicitly imported in my code.
This is a better “pip freeze”. It takes a requirements.in file (for people) and generates a frozen requirements.txt file (for machines). So you can do:
pipreqs . --savepath requirements.in
To update all outdated modules using pip-compile:
pip-compile --output-file requirements.txt requirements.in req
4. pip list — outdated
This is used to list all installed packages that are not up to date with the version on the PyPI index.
5. pip-compile — generate-hashes
This is used to ensure that you actually install all the packages that you wanted to, especially in the face of truncated downloads or network issues.
This tool is used to display a dependency tree like structure of all the installed packages in a virtual environment.
is used to display all modules with the reasons why they are installed i.e. dependencies
This is used to display meta information of packages on the PyPI index.
A microframework based on uvloop, httptools, and learnings of flask
Author: Channel Cat
Author mail: email@example.com
Available versions: 18
Home page: http://github.com/channelcat/sanic/
(0.5.4) Most recent. 09/05/2017 00:49 release date
(0.1.9) Most popular. 1053 downloads
For further reading check out Pipfiles and Pipenv which is built on Pipfiles and virtualenv.