Download and Import Packages in Python (macOS)

Shawn Hymers
2 min readAug 8, 2020

Quick guide to Python packages

In this post I will walk you through installing packages and importing them into Python files. I will also show you how to import your own packages.

I will use Atom for this tutorial. If you don’t have an IDE set up you can check this out: https://medium.com/@shawnhymers/getting-started-with-the-atom-ide-macos-7279b8c119f2

Lets install pandas. Pandas is data analysis package that is very worth learning.

To install it open your terminal and run the following line of code.

pip install pandas

To import it into your python file add the following line to the top of your .py file.

import pandas

Now you can use any pandas functions in your code!

If you don’t want to have to type out pandas every time you want to use one of its functions you can import it as a different name. Commonly pandas is imported as pd. To do this we just need to alter our import code as so:

import pandas as pd

Now you can just use pd to reference the pandas package in your code.

We can also create and import our own packages. To do this, first create a new file in the same folder and name it ‘my_package.py’.

In your new file create this simple function:

def hello_world ():

return print('hellow world!')

Now back in our original file we will import this whole file as a package with this line of code:

import my_package

You can also you ‘as’ to import this as a different name.

Now you can run any functions from the my_package.py file in the new_python_code.py file using the syntax :

my_package.function_name()

--

--