Reputation: 159
I'm trying to train a Tensorflow model in Google Cloud using tensorflow_cloud.
So I have the following code triggering the training:
import tensorflow_cloud as tfc
tfc.run(
requirements_txt="requirements.txt",
distribution_strategy="auto",
docker_image_bucket_name=<bucket-name>
)
I have a simple python file with some util functions let's say its' name is utils.py
So, in the notebook I'm importing this file like so:
from utils import *
My question is - How do I reference this file when running the notebook in GCP?
At the moment I get a module not found error indicating the utils file can't be found.
I'm trying to copy the file to my GCP bucket but it still says it can't find it.
Upvotes: 2
Views: 91
Reputation: 4051
I understand you want to use import
to import and access functions, which you have in a separate .py
file. The error you received happened because the interpreter could not find your package (.py
) in the current or gobal directories. For this reason, you need to add the proper path and import the module.
In order to access them without an error, you need to follow the steps below,
.py
file there;.ipynb
you want to import the file, execute import sys
sys.path.insert(0,"your_path/package")
import your_file as pck
Note: replace the proper fields with your file path and file name
It will be imported successfully. Then you will be able to use the functions within the file.
Upvotes: 1