Reader small image

You're reading from  Mastering Geospatial Analysis with Python

Product typeBook
Published inApr 2018
Reading LevelBeginner
PublisherPackt
ISBN-139781788293334
Edition1st Edition
Languages
Right arrow
Authors (3):
Silas Toms
Silas Toms
author image
Silas Toms

Silas Toms is a long-time geospatial professional and author who has previously published ArcPy and ArcGIS and Mastering Geospatial Analysis with Python. His career highlights include developing the real-time common operational picture used at Super Bowl 50, building geospatial software for autonomous cars, designing computer vision for next-gen insurance, and developing mapping systems for Zillow. He now works at Volta Charging, predicting the future of electric vehicle adoption and electric charging infrastructure.
Read more about Silas Toms

Paul Crickard
Paul Crickard
author image
Paul Crickard

Paul Crickard authored a book on the Leaflet JavaScript module. He has been programming for over 15 years and has focused on GIS and geospatial programming for 7 years. He spent 3 years working as a planner at an architecture firm, where he combined GIS with Building Information Modeling (BIM) and CAD. Currently, he is the CIO at the 2nd Judicial District Attorney's Office in New Mexico.
Read more about Paul Crickard

Eric van Rees
Eric van Rees
author image
Eric van Rees

Eric van Rees was first introduced to Geographical Information Systems (GIS) when studying Human Geography in the Netherlands. For 9 years, he was the editor-in-chief of GeoInformatics, an international GIS, surveying, and mapping publication and a contributing editor of GIS Magazine. During that tenure, he visited many geospatial user conferences, trade fairs, and industry meetings. He focuses on producing technical content, such as software tutorials, tech blogs, and innovative new use cases in the mapping industry.
Read more about Eric van Rees

View More author details
Right arrow

Managing Python packages


After installing Anaconda, it's time to discuss how to manage different Python packages. Anaconda offers several options to do this—Anaconda Navigator, Anaconda Cloud, and the conda package manager.

Managing packages with Anaconda Navigator

After installing Anaconda, you will notice a working folder with various applications inside of it. One of these is Anaconda Navigator, which provides a Graphical User Interface (GUI). You can compare it to Windows File Explorer, that is, an environment to manage projects, packages, and environments. The term environment refers to a collection of packages and a Python install. Notice that this is similar to how you would use virtualenv, but this time using a GUI instead of a command prompt to create one (virtualenv is covered in more detail later in this chapter).

After opening Anaconda Navigator, click the Environments tab on the left of the screen and Anaconda Navigator will provide an overview of existing environments and the packages it contains. There's one pre-defined environment available, a so-called root environment that provides you with 150+ pre-installed Python packages. New environments can be made by clicking the Create button on the bottom of the screen. This will automatically install five default Python packages, including pip, which means you're free to use that too for package management. What's interesting about Anaconda Navigator is that, with every new environment, you can choose a preferred Python version and install from a list of 1000+ packages that are available locally if you installed the default Anaconda version and not Miniconda. This list is available by selecting the option Not Installed from the drop-down menu next to the Channels button. You can easily search and select the packages of your choice by using the Search Packages field and hitting Enter. Mark the packages and install them for the environment of your choice. After installation, the package will be listed by name in the environment. If you click the green box with a checkmark next to the package name, you can choose to mark a package for an upgrade, removal, or specific version installation.

After installing the packages, you can start working with an environment by opening up a terminal, Jupyter Notebook, or another Anaconda application with one mouse click on the arrow button inside of the environment of your choice. If you wish to use an IDE instead of one of the options that Anaconda Navigator offers you, be sure to redirect your IDE to the right python.exe file that is used by Anaconda. This file can usually be found at the following path, which is the default installation path of Anaconda:

C:\Users\<UserName>\Anaconda3\python.exe.

Online searching for packages using Anaconda Cloud

If you are searching for a Python package that is not found in the local list of available Python packages, you can use Anaconda Cloud. This application is also part of Anaconda3 and you can use the Anaconda Cloud application for sharing packages, Notebooks, and environments with others. After clicking on the Anaconda Cloud desktop icon, an internet page will open where you can sign up to become a registered user. Anaconda Cloud is similar to GitHub, as it lets you create a private online repository for your own work. These repositories are called channels.

If you create a user account, you can use Anaconda Cloud from inside Anaconda Navigator. After creating a user account for Anaconda Cloud, open Anaconda Navigator and use your login details to sign into Anaconda Cloud in the upper-right corner of the screen where it says Sign in to Anaconda Cloud. Now, you can upload your own packages and files to a private package repository and search for existing files or packages. 

Managing Python packages with conda

Apart from using Anaconda Navigator and Cloud for package management, you can use conda, a binary package manager, as a command-line tool to manage your package installations. conda quickly installs, runs, and updates packages and their dependencies. conda easily creates, saves, loads, and switches between environments on your local computer. The best ways to install conda are through installing either Anaconda or Miniconda. A third option is a separate installation through Python Package Index (PyPI), but may not be up-to-date so this option is not recommended.

Installing packages with conda is straightforward, as it resembles the syntax of pip. However, it is good to know that conda cannot install packages directly from a Git server. This means that the latest version of many packages under development cannot be downloaded with conda. Also, conda doesn't cover all the packages available on PyPI as pip does itself, which is why you always have access to pip when creating a new environment with Anaconda Navigator (more on pip as we proceed further).

You can verify if conda is installed by typing the following command in a terminal:

>> conda -version

If installed, conda will display the number of the version that you have installed. Installing the package of your choice can be done with the following command in a terminal:

>> conda install <package-name>

Updating an already installed package to its latest available version can be done as follows:

>> conda update <package-name>

You can also install a particular version of a package by pointing out the version number:

>> conda install <package-name>=1.2.0

You can update all the available packages simply by using the --all argument:

>> conda update --all

You can uninstall packages too:

>> conda remove <package-name>

Extensive conda documentation is available at: https://conda.io/docs/index.html.

Managing Python packages using pip

As stated earlier, Anaconda users always have pip available in every new environment, as well as the root folder—it comes pre-installed with every version of Anaconda, including Miniconda. As pip is a Python package manager used to install and manage software packages written in Python, it runs in the command line, as opposed to Anaconda Navigator and Cloud. If you decide not to use Anaconda or anything similar to it, and use a default Python installation from python.org, you can either use easy_install or pip as a package manager. As pip is seen as an improvement over easy_install and the preferred Python package manager for Python 3, we will only discuss pip here. It is recommended to use either pip, conda, Anaconda Navigator, or Cloud for Python package management in the upcoming chapters.

Optionally, as you install Anaconda, three environment variables will be added to your list of user variables. This enables you to access commands such as pip from any system location if you open a terminal. To check if pip is installed on your system, open a terminal and enter:

>> pip

If you don't receive any error message, it means pip is installed correctly and you can use pip to install any package of your choice from the PyPI by using:

>> pip install <package-name>

For Anaconda users, the pip command file should be stored at the following path:

C:\Users\<User Name>\Anaconda3\Scripts\pip.exe.

If pip is not available on your system, you can install pip by following the instructions given at: https://pip.pypa.io/en/latest/installing.

Upgrading and uninstalling the package with pip

Whereas Anaconda Cloud automatically displays a version number of a certain installed package, users choosing to use a default Python installation can use pip to display it through the following command:

>> import pandas
>> pandas.__version__ # output will be a version number, for example: u'0.18.1'

Upgrading a package, for example when there's a new version you'd like to use, can be done as follows:

>> pip install -U pandas==0.21.0

Upgrading it to the latest available version can be done as follows:

>> pip install -U pandas

Uninstalling a package can be done with the following command:

>> pip uninstall <package name>
Previous PageNext Page
You have been reading a chapter from
Mastering Geospatial Analysis with Python
Published in: Apr 2018Publisher: PacktISBN-13: 9781788293334
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
Silas Toms

Silas Toms is a long-time geospatial professional and author who has previously published ArcPy and ArcGIS and Mastering Geospatial Analysis with Python. His career highlights include developing the real-time common operational picture used at Super Bowl 50, building geospatial software for autonomous cars, designing computer vision for next-gen insurance, and developing mapping systems for Zillow. He now works at Volta Charging, predicting the future of electric vehicle adoption and electric charging infrastructure.
Read more about Silas Toms

author image
Paul Crickard

Paul Crickard authored a book on the Leaflet JavaScript module. He has been programming for over 15 years and has focused on GIS and geospatial programming for 7 years. He spent 3 years working as a planner at an architecture firm, where he combined GIS with Building Information Modeling (BIM) and CAD. Currently, he is the CIO at the 2nd Judicial District Attorney's Office in New Mexico.
Read more about Paul Crickard

author image
Eric van Rees

Eric van Rees was first introduced to Geographical Information Systems (GIS) when studying Human Geography in the Netherlands. For 9 years, he was the editor-in-chief of GeoInformatics, an international GIS, surveying, and mapping publication and a contributing editor of GIS Magazine. During that tenure, he visited many geospatial user conferences, trade fairs, and industry meetings. He focuses on producing technical content, such as software tutorials, tech blogs, and innovative new use cases in the mapping industry.
Read more about Eric van Rees