New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Finding third-party modules

From: Python 3 Essential Training

Video: Finding third-party modules

In addition to the modules that distribute with Python in the Python standard library there is also a repository of modules that have been written by other people. This is called PyPI, the Python Package Index, and it's available at this web page. We're going to click on the link here, Python 3 packages, so we can see what packages are available that support Python 3. Of course by the time you look at this, this list will probably be much longer because more-and-more modules are being imported to Python 3 all the time.

Finding third-party modules

In addition to the modules that distribute with Python in the Python standard library there is also a repository of modules that have been written by other people. This is called PyPI, the Python Package Index, and it's available at this web page. We're going to click on the link here, Python 3 packages, so we can see what packages are available that support Python 3. Of course by the time you look at this, this list will probably be much longer because more-and-more modules are being imported to Python 3 all the time.

Just as an example of how to install a module that you find here, I've selected one called bitstring, and what this does is it allows you an easy way of working with strings of bits, and we'll go ahead and we'll download this and install it. And so this is the page and most of the pages look something like this. They've got some documentation. They have a link to the web site where it's been developed and a way to download a module.

And so I've already downloaded this and unpacked it on the computer here and there it is. Go ahead and change into that directory. And we can see that it's this Python file and a setup.py and some other related files. All of the modules that are available on PyPI have a setup.py and it's a standard, and so they all install pretty much the same way. Now I am installing this on Windows.

And the way that you install it on other operating systems is pretty much exactly the same. You run the setup.py script with the argument install. And on Windows, unless you've put Python in your path you'll have to type in the path to Python. On most other systems you won't need to do that. So I am just going to type in the path here. And I say python31, which is the standard place where it installs on a Windows system. And let's say python, and then I am going to give the name of the setup script, which is setup.py and the word install, like that.

And so if you are on a UNIX-based system like a Mac or Linux you probably just type something like Python 3 setup.py install. You do want to make sure that if you have both Python 3 and an earlier version of Python installed on your system that you are running the correct Python when you run the setup.py. If for example you were to run Python 2 and the setup and install, your module would be installed in the path for the Python 2 and not in the path for the Python 3.

So you want to make sure you are running the right Python when you do this. And so in this case that's by using this directory and then Python and setup.py and install. So I am going to go ahead and run that, and there it is it's built it and it's copied it into the site-packages directory, which is where all of your user installable packages are installed. And again if you are on a UNIX system or on any different operating system that will be in a different place, but it'll be called site-packages just like that.

Let me go ahead and change to that directory so we can see what happens here. So this is the site-packages directory on this system, and you see it just has this one module installed. And it installs this egg-info, which is just a lot of information about the module, and that's useful. It installs the .py file and then it also installs this .pyc file. What that is is a complied version of the module. So that when it's run it's actually a little bit more efficient, and this happens at install time.

So we'll go ahead and switch to Eclipse now and we'll take a look at how we use this. Make a working copy of modules.py. Call that modules-working.py. We'll open that up and instead of import sys here we are going to import bitstring, and we'll go ahead and use it. Set a variable.

Now I have already read the documentation from the module. That might be the first thing that you'll want to do. a = bitstring.BitString(bin = 01010101, and I want to put that in quotes because that's a string. So what this does is it allows you to find binary patterns using strings and then use those. We'll go ahead and print it in some different forms. a.hex, a.bin, a.unsigned integer, and we'll save that and run it.

And there we have successfully installed and used a module that we've found on the PyPI index. So the PyPI index is a very useful thing and you want to be careful of course because a lot of people submit modules and they are varying quality, so you want to do a little bit of vetting. Or you may just want to download some modules and look at their source code and learn how other people do things. It's a very valuable resource. And again it gives you the opportunity to leverage other people's work and to not be reinventing the wheel.

So do take a look at the Python index at PyPI and become familiar with what it is and how it works and add it to your quiver of tools.

Show transcript

This video is part of

Image for Python 3 Essential Training
Python 3 Essential Training

87 video lessons · 37646 viewers

Bill Weinman
Author

 
Expand all | Collapse all
  1. 5m 14s
    1. Welcome
      1m 32s
    2. Understanding prerequisites for Python
      2m 4s
    3. Using the exercise files
      1m 38s
  2. 33m 29s
    1. Getting started with "Hello World"
      4m 43s
    2. Selecting code with conditionals
      4m 45s
    3. Repeating code with a loop
      4m 13s
    4. Reusing code with a function
      2m 43s
    5. Creating sequences with generator functions
      2m 46s
    6. Reusing code and data with a class
      4m 39s
    7. Greater reusability with inheritance and polymorphism
      7m 17s
    8. Handling errors with exceptions
      2m 23s
  3. 22m 32s
    1. Installing Python 3 and Eclipse for Windows
      11m 24s
    2. Installing Python 3 and Eclipse for Mac
      11m 8s
  4. 28m 0s
    1. Creating a main script
      3m 27s
    2. Understanding whitespace in Python
      4m 8s
    3. Commenting code
      3m 28s
    4. Assigning values
      3m 37s
    5. Selecting code and values with conditionals
      4m 46s
    6. Creating and using functions
      3m 54s
    7. Creating and using objects
      4m 40s
  5. 31m 23s
    1. Understanding variables and objects in Python
      2m 46s
    2. Distinguishing mutable and immutable objects
      2m 41s
    3. Using numbers
      3m 34s
    4. Using strings
      6m 38s
    5. Aggregating values with lists and tuples
      4m 55s
    6. Creating associative lists with dictionaries
      4m 24s
    7. Finding the type and identity of a variable
      4m 45s
    8. Specifying logical values with True and False
      1m 40s
  6. 9m 42s
    1. Selecting code with if and else conditional statements
      2m 22s
    2. Setting multiple choices with elif
      2m 14s
    3. Understanding other strategies for multiple choices
      2m 38s
    4. Using the conditional expression
      2m 28s
  7. 11m 26s
    1. Creating loops with while
      1m 27s
    2. Iterating with for
      3m 54s
    3. Enumerating iterators
      3m 22s
    4. Controlling loop flow with break, continue, and else
      2m 43s
  8. 23m 28s
    1. Performing simple arithmetic
      2m 14s
    2. Operating on bitwise values
      3m 30s
    3. Comparing values
      3m 32s
    4. Operating on Boolean values
      2m 59s
    5. Operating on parts of a container with the slice operator
      6m 52s
    6. Understanding operator precedence
      4m 21s
  9. 11m 34s
    1. Using the re module
      1m 4s
    2. Searching with regular expressions
      3m 12s
    3. Replacing with regular expressions
      3m 29s
    4. Reusing regular expressions with re.compile
      3m 49s
  10. 9m 10s
    1. Learning how exceptions work
      1m 18s
    2. Handling exceptions
      4m 15s
    3. Raising exceptions
      3m 37s
  11. 23m 1s
    1. Defining functions
      6m 23s
    2. Using lists of arguments
      2m 26s
    3. Using named function arguments
      4m 32s
    4. Returning values from functions
      1m 55s
    5. Creating a sequence with a generator function
      7m 45s
  12. 47m 29s
    1. Understanding classes and objects
      5m 12s
    2. Using methods
      6m 12s
    3. Using object data
      10m 4s
    4. Understanding inheritance
      5m 11s
    5. Applying polymorphism to classes
      7m 13s
    6. Using generators
      9m 48s
    7. Using decorators
      3m 49s
  13. 18m 54s
    1. Understanding strings as objects
      3m 25s
    2. Working with common string methods
      5m 24s
    3. Formatting strings with str.format
      5m 31s
    4. Splitting and joining strings
      2m 49s
    5. Finding and using standard string methods
      1m 45s
  14. 25m 27s
    1. Creating sequences with tuples and lists
      4m 6s
    2. Operating on sequences with built-in methods
      5m 50s
    3. Organizing data with dictionaries
      4m 56s
    4. Operating on character data with bytes and byte arrays
      10m 35s
  15. 11m 46s
    1. Opening files
      2m 4s
    2. Reading and writing text files
      4m 33s
    3. Reading and writing binary files
      5m 9s
  16. 21m 27s
    1. Creating a database with SQLite 3
      6m 56s
    2. Creating, retrieving, updating, and deleting records
      7m 31s
    3. Creating a database object
      7m 0s
  17. 18m 27s
    1. Using standard library modules
      8m 0s
    2. Finding third-party modules
      5m 47s
    3. Creating a module
      4m 40s
  18. 23m 11s
    1. Dealing with syntax errors
      8m 19s
    2. Dealing with runtime errors
      4m 0s
    3. Dealing with logical errors
      4m 22s
    4. Using unit tests
      6m 30s
  19. 19m 56s
    1. Normalizing a database interface
      6m 39s
    2. Deconstructing a database application
      8m 9s
    3. Displaying random entries from a database
      5m 8s
  20. 29s
    1. Goodbye
      29s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.