Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Hello,
I make a script to clean my data. The script uses data from the json files for computation purposes. I store all the script and the json in the library of my project.
So here is how the library editor looks.
I tried to import some function and class in a code recipe, but get the following error.
Is there any way I can import the function defined in the script in the library to a python recipe to make custom transformation? Or, do I have to make a plugin?
Here I attach all files that I upload to the library.
Thank you in advance for your answer.
Hi Nurul,
Welcome to Dataiku community!
When importing new libraries you just added into a Notebook you will need to restart the notebook kernel so the notebook can load these new libraries.
I see you have already created __init__.py in your subfolder. As per out doc here :
https://doc.dataiku.com/dss/latest/python/reusing-code.html
You also don't need to include the lib.python in your import.
can you try changing the after restarting the notebook Kernel and let us know if you still have issues.
from location_validation_function.synonym import batch_synonim, SynonymEntity
Hi Nurul,
Indeed loading JSON files from the python library is not ideal.
You can use Managed folder instead, add the JSON files there and use the Managed folder API to read them, there are several examples here: https://doc.dataiku.com/dss/latest/connecting/managed_folders.html#usage-in-python
Depending on what you are actually storing in these json files you may want to simply define project variables instead since that is also just JSON. You can then read the variables with: via https://doc.dataiku.com/dss/latest/code_recipes/variables_expansion.html#python
Hi Nurul,
Welcome to Dataiku community!
When importing new libraries you just added into a Notebook you will need to restart the notebook kernel so the notebook can load these new libraries.
I see you have already created __init__.py in your subfolder. As per out doc here :
https://doc.dataiku.com/dss/latest/python/reusing-code.html
You also don't need to include the lib.python in your import.
can you try changing the after restarting the notebook Kernel and let us know if you still have issues.
from location_validation_function.synonym import batch_synonim, SynonymEntity
Hi Alex,
The solution works! Thank you so much.
sorry, but after I can import the module, I got another error
the file is in the same folder as the .py script.
Where should I put these json files?
Hi Nurul,
Indeed loading JSON files from the python library is not ideal.
You can use Managed folder instead, add the JSON files there and use the Managed folder API to read them, there are several examples here: https://doc.dataiku.com/dss/latest/connecting/managed_folders.html#usage-in-python
Depending on what you are actually storing in these json files you may want to simply define project variables instead since that is also just JSON. You can then read the variables with: via https://doc.dataiku.com/dss/latest/code_recipes/variables_expansion.html#python
Thank you so much for your help. I managed to create and run the recipe.
Once again, thank you๐
Hi,
I am facing same issue while importing the modules we have created. I am following all the basic rules needed for import but still have the issue . can someone help on what could i be missing here.