Chapter 5. Advanced Django in PTVS

Once we look at how a Django development environment in Visual Studio with PTVS is set up, we can start analyzing some powerful libraries for Django and how to use them in Visual Studio. Over the years, lots of developers have created powerful libraries and tools for Django that speed up various aspects of the development cycle. We are going to take a closer look at some of them here to see how they integrate in Visual Studio and PTVS.

In this chapter, we will analyze two libraries that are useful for a Django developer in two different aspects: automatizing tasks using the Fabric library, and managing model migrations on Django with South.

Library management

We have already learned how to install new packages in PTVS using the GUI tools that it provides. Now, we will learn more about the criteria for choosing one package index over another; in other words, when to choose easy_install over pip.

Generally speaking, using pip is much better than using easy_install, and there are major reasons for this. As Ian Bicking, the creator of pip, wrote in his own introduction to pip, the advantages are as follows:

  • All packages are downloaded before installation. As a result, partially completed installation doesn't occur.
  • Care is taken when presenting useful output on the console.
  • The reasons for actions are being tracked. For instance, if a package is being installed, pip keeps track of why that package was required.
  • Error messages should be useful.
  • The code is relatively concise and cohesive, making it easier to use programmatically.
  • Packages don't have to be installed as egg archives; they can be installed flat (while keeping the egg metadata).
  • Native support is available for other version control systems (Git, Mercurial, and Bazaar).
  • Uninstallation of packages is easy.
  • It is simple to define, has fixed sets of requirements, and reliably reproduces a set of packages.

It may seem that there are no reasons to choose easy_install over pip. However, this is where careful consideration is needed.

There is a caveat that makes the choice really hard for Windows environments: some libraries or dependencies are written in Python C, which is a way for Python to call libraries written in C/C++. To compile these libraries on your Windows machine, you have to install the exact same version of the original compiler that has been used to compile to the original interpreter. For example, you will need the C++ compiler of Visual Studio 2008 if you use Python 2.7 or Visual Studio 2010 for Python 3.

This is due to a long tradition where Python extension modules must be built with the same compiler version (more specifically, a CRT version) as Python itself, which is mentioned at https://mail.python.org/pipermail/python-list/2010-April/573606.html.

Using the easy_install package installer, the precompiled packages are downloaded and installed into the system's site-packages folder.

Note

A rule of thumb: if the library you are trying to install on your Windows machine has Python C extensions in it, it's far better to choose easy_install. For all other cases, pip is way better.

If you don't know what kind of library you are importing, you should go with pip. If it encounters a problem during the compilation process of the installation, you can uninstall the library and reinstall it using easy_install.

Generally, most libraries that have low-level capabilities (for example, cryptography, graphics, and mathematical functions) and interaction with other software (for example, drivers) use Python C extensions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.70.170