Learning Python for Forensics
上QQ阅读APP看书,第一时间看更新

Installing third-party libraries

We know that we do not need to install standard modules because they come with Python, but what about third-party modules? The Python Package Index is a great place to start looking for third-party libraries. This can be found at https://pypi.org/. This service allows tools, such as pip, to install packages automatically. If an internet connection is not available or the package is not found on PyPi, a setup.py file can usually be used to install the module manually. The examples of using pip and setup.py are shown later. Tools such as pip are very convenient as they handle the installation of dependencies, check whether items are already installed, and suggest upgrades if an older version is installed. An internet connection is required to check for online resources, such as dependencies and newer versions of a module; however, pip can also be used to install code on an offline machine.

These commands are run in the Terminal or Command Prompt, not the Python interpreter. Please note that in the example mentioned below, full paths may be necessary if your Python executable is not included in the current environment's PATH variable. pip may need to be run from an elevated console, either using sudo or an elevated Windows Command Prompt. Full documentation for pip can be found at http://pip.pypa.io/en/stable/reference/pip/:

$ pip install python-registry==1.0.4
Collecting python-registry
Collecting enum34 (from python-registry)
Using cached https://files.pythonhosted.org/packages/af/42/cb9355df32c69b553e72a2e28daee25d1611d2c0d9c272aa1d34204205b2/enum34-1.1.6-py3-none-any.whl
Installing collected packages: enum34, python-registry
Successfully installed enum34-1.1.6 python-registry-1.0.4

$ pip install yarp==1.0.17
https://github.com/msuhanov/yarp/archive/1.0.17.tar.gz
Collecting https://github.com/msuhanov/yarp/archive/1.0.17.tar.gz
Downloading https://github.com/msuhanov/yarp/archive/1.0.17.tar.gz
\ 716kB 12.8MB/s
Building wheels for collected packages: yarp
Running setup.py bdist_wheel for yarp ... done
Stored in directory: C:\USERS\...\APPDATA\LOCAL\TEMP\pip-ephem-wheel-cache-78qdzfmy\wheels\........
Successfully built yarp
Installing collected packages: yarp
Successfully installed yarp-1.0.17