Python 3 – Importing Modules (Mac OSX)

I’m currently playing around with Python 3 on Mac OSX. One of the first issues I’ve hit is importing modules. During a Python script the import command is used to call on other modules so that their functionality can be used in the script.

However before Python can import a module, the module must be installed. This installation takes place outside of Python and within the Operating System (OS). I also ran into an issue that MacOSX Terminal did not understand the pip command. I enabled pip/resolved this by firing up a terminal and typing:

sudo python -m ensure pip –default-pip

Then to install modules type:

sudo python3 -m pip install

e.g. to install the “requests” module type:

sudo python3 -m pip install requests

Note: On Mac OSX if you type sudo python instead of sudo python3 then Mac OSX installs the module into Python 2 (which comes with Mac OSX High Sierra).

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.