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")
Related
I'm trying to create a new virtualenvironment for some repos but seem to be running into a bunch if issues in my terminal, these are the errors I get:
zsh: /usr/local/bin/pip: bad interpreter: /usr/local/opt/python#2/bin/python2.7: no such file or directory
OR this issue:
ERROR: It thinks sys.prefix is '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7' (should be '/Users/USERNAME_HERE/.virtualenvs/returns-backend')
ERROR: virtualenv is not compatible with this system or executable
I get this error when running: brew link --overwrite python from here
Linking /usr/local/Cellar/python/3.7.7... Error: Cannot link python
Another version is already linked: /usr/local/Cellar/python/3.7.6_1
I also get this issue when running the following command: pip3 install --upgrade pip from this comment
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 11, in <module>
load_entry_point('pip==19.3.1', 'console_scripts', 'pip3')()
File "/usr/local/lib/python3.7/site-packages/pip/_internal/main.py", line 45, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/usr/local/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 96, in create_command
module = importlib.import_module(module_path)
File "/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/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 "/usr/local/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 23, in <module>
from pip._internal.cli.req_command import RequirementCommand
File "/usr/local/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 17, in <module>
from pip._internal.index import PackageFinder
ImportError: cannot import name 'PackageFinder' from 'pip._internal.index' (/usr/local/lib/python3.7/site-packages/pip/_internal/index/__init__.py)
I haven't touched the terminal in a long time (2+ years) and don't remember what I used to set these up as my documentation wasn't great last time when starting to code. I think I remember using brew before to set this stuff all up, but now I'm just worried about making any more changes that might break things even further.
Any help with commands that might not be as intrusive/possibly making this problem bigger?
I'm tyring to use this program (https://github.com/tbabej/uadt) to test my pcap captures and do some machine learning. I use the command git clone to have everything on my pc, then I use "pip -r install requirements.txt" and then I execute "setup.py install".
Then I need to generate my dataset, so I go to /uadt/uadt/analysis/ and run dataset.py as stated in the Readme, but I get the error
from uadt import config
ImportError: cannot import name 'config' from 'uadt'
What am I doing wrong? Is there another way to install it?
I just need the files in the analysis folder because I've already done the other steps on my own.
Traceback (most recent call last):
File "/usr/local/bin/uadt-dataset", line 33, in <module>
sys.exit(load_entry_point('uadt==0.8.0', 'console_scripts', 'uadt-dataset')())
File "/usr/local/bin/uadt-dataset", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/lib/python3.9/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/usr/local/lib/python3.9/dist-packages/uadt-0.8.0-py3.9.egg/uadt/analysis/dataset.py", line 26, in <module>
from uadt.analysis.flow import Flow
File "/usr/local/lib/python3.9/dist-packages/uadt-0.8.0-py3.9.egg/uadt/analysis/flow.py", line 13, in <module>
from uadt import config
ImportError: cannot import name 'config' from 'uadt' (/usr/local/lib/python3.9/dist-packages/uadt-0.8.0-py3.9.egg/uadt/__init__.py)
You can copy the config.py.in file into the uadt folder.
This could fix your import issue.
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
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
I'm trying to create some Python3 Azure MySQL jobs in azure functions using SQL Alchemy.
Function runs locally with func start without a problem.
It's in fresh venv, on fresh Linux VM to exclude any possible package dependencies.
Deploying to Azure via func azure functionapp publish {app_name} --build remote without any problems.
But upon calling the function I'm getting:
"name '_mysql' is not defined"
It seems like the MySQLdb module is not installed, but my requirements.txt contains
mysqlclient==2.0.1 and it's installing properly. Even weirder, it works great when I'm running the function locally.
This is the full error, sorry for the formatting:
Result: Failure Exception: NameError: name '_mysql' is not defined Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 262, in _handle__function_load_request func = loader.load_function( File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 32, in call return func(*args, **kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 76, in load_function mod = importlib.import_module(fullmodname) File "/usr/local/lib/python3.8/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 961, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed 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 783, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/home/site/wwwroot/vm/__init__.py", line 4, in <module> from __app__.vm.get_vm import insert_vms File "/home/site/wwwroot/vm/get_vm.py", line 3, in <module> from __app__.shared.db.models import VM File "/home/site/wwwroot/shared/db/models.py", line 3, in <module> from __app__.shared.db.base import Base, engine File "/home/site/wwwroot/shared/db/base.py", line 12, in <module> if not database_exists(url): File "/home/site/wwwroot/.python_packages/lib/site-packages/sqlalchemy_utils/functions/database.py", line 462, in database_exists engine = sa.create_engine(url) File "/home/site/wwwroot/.python_packages/lib/site-packages/sqlalchemy/engine/__init__.py", line 500, in create_engine return strategy.create(*args, **kwargs) File "/home/site/wwwroot/.python_packages/lib/site-packages/sqlalchemy/engine/strategies.py", line 87, in create dbapi = dialect_cls.dbapi(**dbapi_args) File "/home/site/wwwroot/.python_packages/lib/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 118, in dbapi return __import__("MySQLdb") File "/home/site/wwwroot/.python_packages/lib/site-packages/MySQLdb/__init__.py", line 24, in <module> version_info, _mysql.version_info, _mysql.__file__
Ok, this was my error from the beginning - I've forgot to put the driver in the connection string for the DB - ex. mysql+pymysql://mysqladmin(...)
I think it's a problem with mysqlclient.
Link below may helpful, be sure that MySQL development headers and libraries are installed
https://pypi.org/project/mysqlclient/
If everything is done and problem still exits, you can add the path of your mysql's library into LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/path/to/mysql/lib