Import Python Packages

Import External Python Packages

Before importing them we must install them with the Command:

pip install external_package

Once installed to import them simply call the package name using the import command

import external_package

 

Import own Python Packages

Import packets in Python

If it is in the root directory

Root File: main.py

import modulo1
modulo1.print()

 

File to Import: module1.py

def print():
    print('Works')

If it is inside a package

Root File: main2.py

import package.module2 as m2 # you can put an alias to simplify calls 
m2.print()

File to Import: module2.py

def print():
    print('Works')