I am finalizing a project where I need to split the requirements.txt , helper_functions.py and , libraries.py -libraries that are used within the functions- into (3) separate files for code beautification .
I created the 3 files, uploaded them on my cloud and made them accessible to my google Colab notebook:
I downloaded the
requirements.txtand installed the packages every time I run the jupyter notebook using the command!pip install -r requirements.txtI downloaded the
helper_functionsand imported them into my environment using the commandfrom helper_functions import *where I can see them.This is the problem now, I downloaded the libraries.py and tried to import them using using the command
from libraries import *or%run -i libraries.py. The problem I have is when I try to call any of the functions that require one of the libraries e.g boto3 library or the shortcut of np (though both of them exist in my libraries.py file), I get an error ofname 'boto3' is not defined name 'np' is not defined
Here are the snapshots of my files that are loaded into my Colab environment
`requrinments.txt`
boto3
numpy
`libraries.py file`
import boto3
import numpy as np
`helper_functions.py file`
def load_data(input):
data = np.(…..)
what should I do ?
Python modules are imported into a given namespace. To use a module of a module you can access it by module.submodule. However this is terrible to do and you should just about always import them directly into your module since almost all of the time they will be identical.
The above should be akin to the below for all non-hacky code.