Installing Python Modules into the Correct Python Version on a Mac

I’m doing some testing of the Feedparse Python module. The install instructions seem simple enough.

sudo pip install feedparser

However, on trying to import the module into a Python 3.6 console I received an error message, “ModuleNotFoundError: No module named ‘feedparser'”.

Pauls-MacBook-Pro:~ paulcunningham$ python3.6
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import feedparser
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'feedparser'

I ran the installer again, and the error message this time indicated that the module was installed for Python 2.7, which is not the version I’m tying to use.

Pauls-MacBook-Pro:tst paulcunningham$ sudo pip install feedparser
Password:
Requirement already satisfied: feedparser in /Library/Python/2.7/site-packages

After some reading of the Python docs for installing modules, I learned that it’s necessary to run the version of Pip for the Python version you’re installing the new module for.

python3.6 -m pip install feedparser

Feedparser is now available for me to use in Python 3.6.

Pauls-MacBook-Pro:tst paulcunningham$ python3.6
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import feedparser
>>> 

Photo by Simon Abrams on Unsplash

By Paul Cunningham

Paul is a writer and entrepreneur living in Brisbane, Australia. He enjoys spending time with his family and running in the mountains. Paul was the founder of Practical 365, a former Microsoft MVP, and Pluralsight trainer. Paul is also on Twitter and Instagram.