Failed to load the component rasa - python

I am using rasa as a python library. Here is my directory structure
chat-bot/
bots/
models/
rasa/
my-model.tar.gz
rasa_bot.py
projects/
rasa/
actions/
components/
data_processing.py
data/
nlu.yml
stories.yml
config.yml
domain.yml
Here is how my config.yml
language: en
pipeline:
- name: components.data_processing.DataProcessingComponent
- name: WhitespaceTokenizer
- name: CountVectorsFeaturizer
and this is how I train the model
rasa train --fixed-model-name my-model --out ../../bots/models/rasa/
And in rasa_bot.py This is how I am loading the model
model = RasaBot.__get_model("my-model.tar.gz")
# get the agent from model and action server
ACTION_ENDPOINT = os.getenv('ACTION_ENDPOINT')
agent = Agent.load(
model,
action_endpoint=EndpointConfig(ACTION_ENDPOINT)
)
and __get_model method
#staticmethod
def __get_model(modelName):
MODEL_LOCATION = os.environ.get('MODEL_LOCATION')
return '{}/{}'.format(MODEL_LOCATION, modelName)
but this is showing this error
Failed to load the component 'components.data_processing.DataProcessingComponent'. Failed to find module 'components.data_processing'. Either your pipeline configuration contains an error or the module you are trying to import is broken (e.g. the module is trying to import a package that is not installed). Traceback (most recent call last):
File "c:\chat-bot\env37\lib\site-packages\rasa\nlu\registry.py", line 121, in get_component_class
return rasa.shared.utils.common.class_from_module_path(component_name)
File "c:\chat-bot\env37\lib\site-packages\rasa\shared\utils\common.py", line 37, in class_from_module_path
m = importlib.import_module(module_name)
File "C:\Users\sgarg\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'components'

Could you add an empty __init__.py file to your components folder? That way the folder is detected as a Python module.
Note that I'm assuming that you're running the rasa train command from the projects/rasa folder here.

In my rasa_bot.py, I added
RASA_DIR = os.getcwd() + "//projects//rasa"
sys.path.append(RASA_DIR)
and it worked

Related

No file found when converting a python project with NUITKA with library OWLREADY2

After I converted my python project with NUITKA and I started running the following message appeared:
Owlready2 * Warning: optimized Cython parser module 'owlready2_optimized' is not available, defaulting to slower Python implementation
Traceback (most recent call last):
File "/user/try.dist/try.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "/user/try.dist/owlready2/__init__.py", line 35, in <module owlready2>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "/user/try.dist/owlready2/reasoning.py", line 41, in <module owlready2.reasoning>
FileNotFoundError: [Errno 2] No such file or directory: '/user/try.dist/owlready2/pellet'
Indicating that after I compiled the program some files were not found.
The code that I run was python3 -m nuitka --follow-imports --enable-plugin=numpy --onefile try.py
and the code that I compiled was just simple this:
from owlready2 import *
onto = get_ontology("file:///user/ontologies/try.owl").load()
with onto:
types.new_class("Drug", (Thing,))
onto.save()
So simple there was something wrong with the library.
If anyone knows what to do it will be helpful.
Thanks in advance.
I have changed the location of the file for privacy

Creating Python Package (setuptools) - No module named

I'm trying to create a python package for the first time, using setuptools.
Let's imagine my package is named qwerty.
Here's my project structure:
qwerty (folder)
++ src (folder)
--++ __init__.py
--++ control.py
--++ modes.py
--++ data.dic
--++ utils.py
--++ version.py
--++ qwerty.py
++ __init__.py
++ __main__.py
CHANGELOG.md
commands.txt
README.md
image.gif
setup.py
My setup.py contains the following code:
import setuptools as st
import os
exec(open(os.path.join(os.path.abspath(os.path.dirname(__file__)), "qwerty/src/version.py")).read())
st.setup(
include_package_data=True,
version=__version__,
(...)
package_data={"": ["*.dic"]},
packages=st.find_packages(where="qwerty"),
package_dir={"": "qwerty"},
entry_points={"console_scripts": ["qwerty=qwerty.__main__:main"]}
)
And my __main__.py contains the following code:
from .src.qwerty import main
if __name__ == "__main__":
main()
I'm using the following command to create/install the package:
$ pip install .
When I install the program, it is installed in /usr/local/bin. My goal here is that the final binary executes the main function located in qwerty/src/qwerty.py. But I must be doing something wrong because after installing the package, when I run the program, I get the following output:
Traceback (most recent call last):
File "/usr/local/bin/qwerty", line 33, in <module>
sys.exit(load_entry_point('qwerty==1.0.3', 'console_scripts', 'qwerty')())
File "/usr/local/bin/qwerty", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
module = import_module(match.group('module'))
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'qwerty'
I already tried using entry_points={"console_scripts": ["qwerty=qwerty.src.qwerty:main"]} as the entry point in setup.py, but got the exact same output.
Can someone try to explain me what I'm doing wrong and how I can fix this problem?
Thank you in advance.

ModuleNotFoundError: No module named 'PySide2' while trying to use poetry env

i'm trying to use slicereg (https://github.com/brainglobe/slicereg) for data registration.
after import code from github page and install poetry to run slicereg i keep getting the following error :
The virtual environment found in ~\.conda\envs\sliceregenv seems to be broken.
Recreating virtualenv slicereg-6kSWvOuc-py3.8 in ~\AppData\Local\pypoetry\Cache\virtualenvs\slicereg-6kSWvOuc-py3.8
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "~\.conda\envs\sliceregenv\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "~\slicereg\slicereg\main.py", line 3, in <module>
from PySide2.QtWidgets import QApplication
ModuleNotFoundError: No module named 'PySide2'
Pyside2 is already installed in my env using pip.
Any advice on how to resolve this issue ?
Thx
Seems to be an issue, poetry fails to recognize conda environments as valid
see more at https://github.com/python-poetry/poetry/issues/4566
Remain unresolved for the current release (1.1.12)
Update : https://github.com/python-poetry/poetry/issues/5907

#quickfix import failed in windows10

system: windows 10,
language: python 3.6.5
I installed the quickfix 1.15.1 by pip install quickfix-1.15.1-cp36-cp36m-win_amd64.whl downloaded from web.
When I try like:
import quickfix
errors:
*Connected to pydev debugger (build 202.6948.78)
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\quickfix.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\ProgramData\Anaconda3\lib\site-packages\quickfix.py", line 21, in <module>
_quickfix = swig_import_helper()
File "C:\ProgramData\Anaconda3\lib\site-packages\quickfix.py", line 20, in swig_import_helper
return importlib.import_module('_quickfix')
File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed: The specified module could not be found.
Process finished with exit code 1*
And I had installed .Net 5.0
If you are sure that quickfix is correctly installed in your environment and the PYTHONPATH has access to this environment, then you can try to check the option 'Load conda env vars before run?' on Window -> Preferences -> PyDev -> Interpreters -> Python Interpreter.
It's possible that the import is failing because that package is using an environment variable to load the modules, and PyDev by default is not loading this variable before running the script.

Sphinx throws KeyError exception

I have a python flask script inside a docker. This script get some environment variable from the docker-compose in this way:
app = Flask(__name__)
DEFAULT_PSW = os.environ['DEFAULT_PSW']
#app.route("/")
def manager():
...
I wanted to document it using Sphinx. I was able to configure it but when I run "make html" I get this exception:
WARNING: autodoc: failed to import module 'main'; the following exception was raised:
Traceback (most recent call last):
File "/home/lorenzo/.local/lib/python3.7/site-packages/sphinx/ext/autodoc/importer.py", line 32, in import_module
return importlib.import_module(modname)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/lorenzo/Desktop/Dev/project/script/manager_flask/manager/manager/main.py", line 20, in <module>
DEFAULT_PSW = os.environ['DEFAULT_PSW']
File "/usr/lib/python3.7/os.py", line 679, in __getitem__
raise KeyError(key) from None
KeyError: 'DEFAULT_PSW'
If I've understood well how sphinx works the problem is that sphinx will try to "compile" my script and, of course, during this process it won't find the environment variable. What can I do?
EDIT:
Steps that I did to get this error:
Create folder called docs
Inside the docs folder started sphinx-quickstart leaving everything by default except for Author and Project name.
Edited the conf.py (this file can be found in the repository in the comment)
Generate the rst file with sphinx-apidoc
Create folder modules and added the file scp_handler.rst and main.rst
Updated the index.rst adding the path to the new generated file
Ran "make html".
For documentation purposes set and export the key in the conf.py file:
os.environ("DEFAULT_PSW", "default_psw")

Categories

Resources