Python offers the option of expanding their functionality by installing new packages, something similar to DLLs in Visual Basic. This way, you haved more resources for using within your scripst and software.
Let’s open a MS-DOS console, and go to the directory that constains Python, in my case c:\python27, for versión 2.7.
First, let’s ckeck inside the scripts directory if we can use easy_install:
Let’s install pip, another tool that allow the user to install and work with packages, by using easy_install:
Again, let’s list the files on the scripts directory, and now we can use both, either pip either easy_install:
Let’s install “uncertainties” package for working with standart desviations.
Let’s verify we still cannot use NumPy:
So, let’s install with easy_install:
Let’s open a new console, and let’s check again:
To install MySQLDb, we can execute the command:
pip install mysql-python
But,nothing is installed because we already have it installed (lucky me!!)
Let’s use it in a small script, trying to connect to a MySQL database, and let’s print a few records for one table. Just code something like this (modify the options to your user, password, server and database):
sql='SELECT idparametro, parametro FROM parametros LIMIT 5;'
for registro in resultado:
print registro , '|' , registro
And the results:
And that’s it! This is the way (two ways) of adding new packages and modules to Python!
Have a nice day!