In Nifi “ExecuteScript” processor. When the python script (running from “ExecuteScript” processor) trying to import “unidecode” module throwing error saying “No module found” and the “unidecode” module is installed for Python 2.x on Nifi Server.
Will this work on python 3 or do we require to use different processor.
I tried to resolve a error
Check the documentation of the processor ExecuteScript
The engine listed as "python" in the list of available script engines is actually Jython, not Python. When using Jython, you cannot import pure (CPython) modules such as pandas
Related
I am trying to use ExecuteScript to execute a python script. I logged in as root and installed all the necessary python packages for one my python packages in the HDF sandbox. I am able to import this package from a python prompt. But when I try to import it from within ExecuteScript I get import error for my package which was installed. Why does NiFi not find the package?
I am trying to port python 2.7 code to python 3.7 code
I am seeing an "import hotshots" in a file but getting a
ModuleNotFoundError: No module named 'hotshot'
I can't seem to find that module anywhere online. Is this a python 2.7 specific package replaced with something else ? I had that case with cStringIO
Additional info : this is implemented in a Django project. Maybe an older Django lib ? I am trying to port this code from Django 1.8 to 2.2
What I tried to do :
- pip install --upgrade hotshot
No matching distribution found for hotshot
Looking for hotshot on The Python Package Index
No library with that name
What it is used for ? The only line where it is used is
prof = hotshot.Profile(final_log_file)
The whole project code is available here :
https://github.com/EbookFoundation/fef-questionnaire,
the file using "hotshot" is "profiler.py". Additionnally, there are no "hotshot.py" file in the whole project.
Finally found something. hotshot was a Python profiler (https://docs.python.org/2/library/profile.html)
From https://docs.python.org/2/library/hotshot.html :
hotshot was an experimental C module that focused on minimizing the
overhead of profiling, at the expense of longer data post-processing
times. It is no longer maintained and may be dropped in a future
version of Python.
I simply have to replace hotshot by a newer Python profiler, compatible with Python 3 :
https://docs.python.org/3/library/profile.html
So either profile or cProfile.
I just started learning to customize my foorprint in Kicad via python scripts. I got stuck on “import pcbnew” because it gave me the error “no module name pcbnew” all the time. I checked my Kicad folder and found all the py examples for script foorprint wizard, but there’s no file named “pcbnew.py”.
I’m wondering if it’s because I’m using python3.5 rather than python2.7 and how can I fix this problem. Should I download the pcbnew script from somewhere like Kicad Github (I searched a lot but didn’t find any really helpful solutions…)? Or should I re-install my Kicad or python? My Kicad version is 5.0.
Thanks a lot!
Kicad includes it own version of Python (Version 2.7.13 at time of writing for Kicad 5.1 but moving to python 3 shortly). You can access Kicad python via the Pcbnew python terminal Tools > Scripting console.
If you wish to run a script you have a couple of options.
Run it using the inbuilt python 2.7 using either the scripting console or specifying the Kicad python version in the shebang line (you will have to search for this but, in macOS, for instance it is found in /Applications/Kicad/kicad.app/Contents/Frameworks/Python.framework/Versions/Current/bin/python)
Import the kicad site-packages into the python environment you are using.
import sys
sys.path.insert(0,"/Applications/Kicad/kicad.app/Contents/Frameworks/python/site-packages/")
import pcbnew
I have been trying to run a python script in NiFi's ExecuteScript processor. Though the catch here is that I don't have server file location access and all the python libraries are installed at "/data/jython", "/data/jython/Lib/site-packages/" and "data/nltk"
Below is the import section of my python script:
import json, traceback, pycountry, requests, geocoder, re, sys, nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer
from nltk.corpus import stopwords
from java.nio.charset import StandardCharsets
from org.apache.commons.io import IOUtils
from org.apache.nifi.processor.io import StreamCallback
from org.python.core.util import StringUtil
I have added path reference to the packages/libraries:
Heres the screenshot of the error message:
Is there something I am missing? I have referred to another answer here, but couldn't figure out whats wrong with my code.
As the other answers state, Apache NiFi's ExecuteScript processor uses Jython, not Python. There is a limitation on the Jython library that it cannot handle native modules (modules that end in .so or are compiled C code, etc.). It is very likely that the pycountry module contains some native module. You can try a work-around proposed by Matt Burgess on the NiFi Developers Mailing List here.
ExecuteScript processor uses its own Jython Engine to execute your python scripts.
As the libraries which you are importing are not available in NIFI inbuild Jython Engine its throwing error.
SOLUTION:
If python is already installed on our machine with all those libraries (the same machine where your NIFI is installed) you can use that python engine
to execute your script. you can execute your python code using ExecuteProcess processor. see the configuration of ExecuteProcess.
The following code produces an error message in the Processing IDE:
from pyfirmata import Arduino,util
"No module named pyfirmata"
I have no problem running the code directly in the python 2.7 interpreter.
But, I can't access the Processing API from the interpreter.
You'll have to place the library in question inside your sketch folder. Python Mode doesn't use your system python, and cannot see any of the modules installed there.