Why is importlib not able to import a module two levels up - python-import

I am trying to import a module with importlib but I am get No module named 'configuration'
This is my directory
I am trying to run app.py which loads configuration two levels up
I tried using
importlib.import_module( 'configuration' )
configuration_module = importlib.import_module( '.config_loader', package='configuration' )
it's not able to load configuration
--home
---configuration
---config.py
--- init.py
---restful
--- init.py
---application
--- app.py
--- config.py
--- __init__py
Traceback (most recent call last):
File "application/app.py", line 214, in <module>
app = create_app()
File "application/app.py", line 39, in create_app
importlib.import_module( 'configuration' )
File "/usr/local/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 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'configuration'

Related

cannot create piepenv in linux ubuntu

hello everyone…i have problem in launching venv using pipenv…i never had this problem in windows…I have recently migrated to linux Ubuntu…so i cannot solve this problem…I would be grateful if someone could help me
Creating a virtualenv for this project...
Pipfile: /media/sasan/F/my projects/Djprojects/newprj/Pipfile
Using /usr/bin/python3 (3.10.4) to create virtualenv...
⠸ Creating virtual environment...created virtual environment CPython3.10.4.final.0-64 in 106ms
creator CPython3Posix(dest=/home/sasan/.local/share/virtualenvs/newprj-cXkKfH7p, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/sasan/.local/share/virtualenv)
added seed packages: pip==22.2.2, setuptools==65.3.0, wheel==0.37.1
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
✔ Successfully created virtual environment!
Traceback (most recent call last):
File "/usr/bin/pipenv", line 33, in <module>
sys.exit(load_entry_point('pipenv==11.9.0', 'console_scripts', 'pipenv')())
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/cli/options.py", line 57, in main
return super().main(*args, **kwargs, windows_expand_args=False)
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/vendor/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/cli/command.py", line 397, in shell
do_shell(
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/core.py", line 2520, in do_shell
ensure_project(
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/core.py", line 525, in ensure_project
ensure_virtualenv(
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/core.py", line 458, in ensure_virtualenv
do_create_virtualenv(
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/core.py", line 959, in do_create_virtualenv
project._environment = Environment(
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/environment.py", line 79, in __init__
self._base_paths = self.get_paths()
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/environment.py", line 390, in get_paths
c = subprocess_run(command)
File "/home/sasan/.local/lib/python3.10/site-packages/pipenv/utils/processes.py", line 75, in subprocess_run
return subprocess.run(
File "/usr/lib/python3.10/subprocess.py", line 501, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.10/subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.10/subprocess.py", line 1842, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/sasan/.local/share/virtualenvs/newprj-cXkKfH7p/bin/python'

*SOLVED* Error when trying to create the microros firmware with generate_lib as RTOS

I'm currently trying to make a custom message for a micro-ROS - Teensy communicaton. I found this tutorial on how to include custom ROS messages in micro-ROS. The first thing this tutorial says I should do is to go to "firmware/mcu_ws". So I tried to make this folder with the ros2 run micro_ros_setup create_firmware_ws.sh generate_lib command, but I always got this output.
I already tried reinstalling micro-ROS, reinstalling python3 and reinstalling the python3-catking-pkg, but nothing worked.
I'd really appreciate any help I can get.
(I had to remove the first 40 lines or so, because of the maximum character length, but they were also just cloning processes)
=== ./ros2/rosidl_defaults (git) ===
Cloning into '.'...
=== ./ros2/test_interface_files (git) ===
Cloning into '.'...
=== ./ros2/unique_identifier_msgs (git) ===
Cloning into '.'...
...........
=== ./eProsima/Micro-CDR (git) ===
Cloning into '.'...
=== ./eProsima/Micro-XRCE-DDS-Client (git) ===
Cloning into '.'...
=== ./uros/micro_ros_msgs (git) ===
Cloning into '.'...
=== ./uros/micro_ros_utilities (git) ===
Cloning into '.'...
=== ./uros/rcl (git) ===
Cloning into '.'...
=== ./uros/rclc (git) ===
Cloning into '.'...
=== ./uros/rcutils (git) ===
Cloning into '.'...
=== ./uros/rmw_microxrcedds (git) ===
Cloning into '.'...
=== ./uros/rosidl_typesupport (git) ===
Cloning into '.'...
=== ./uros/rosidl_typesupport_microxrcedds (git) ===
Cloning into '.'...
=== ./uros/tracetools (git) ===
Cloning into '.'...
Crosscompiled environment: cleaning path
[0.683s] WARNING:colcon.colcon_ros.prefix_path.catkin:The path '/home/fabi/projects/install/example_interfaces' in the environment variable CMAKE_PREFIX_PATH doesn't exist
[0.683s] WARNING:colcon.colcon_ros.prefix_path.catkin:The path '/home/fabi/projects/install/microxrcedds_client' in the environment variable CMAKE_PREFIX_PATH doesn't exist
[0.684s] WARNING:colcon.colcon_ros.prefix_path.catkin:The path '/home/fabi/projects/install/microcdr' in the environment variable CMAKE_PREFIX_PATH doesn't exist
[0.684s] WARNING:colcon.colcon_ros.prefix_path.catkin:The path '/home/fabi/projects/install/micro_ros_agent' in the environment variable CMAKE_PREFIX_PATH doesn't exist
[0.684s] WARNING:colcon.colcon_ros.prefix_path.catkin:The path '/home/fabi/projects/install/CarCom' in the environment variable CMAKE_PREFIX_PATH doesn't exist
[0.684s] WARNING:colcon.colcon_ros.prefix_path.catkin:The path '/home/fabi/projects/install/MXObjects' in the environment variable CMAKE_PREFIX_PATH doesn't exist
[0.684s] WARNING:colcon.colcon_ros.prefix_path.catkin:The path '/home/fabi/projects/install/MXJoystick' in the environment variable CMAKE_PREFIX_PATH doesn't exist
[0.684s] WARNING:colcon.colcon_ros.prefix_path.catkin:The path '/home/fabi/projects/microros_ws/install/microxrcedds_client' in the environment variable CMAKE_PREFIX_PATH doesn't exist
[0.684s] WARNING:colcon.colcon_ros.prefix_path.catkin:The path '/home/fabi/projects/microros_ws/install/microcdr' in the environment variable CMAKE_PREFIX_PATH doesn't exist
Starting >>> ament_package
Starting >>> ament_lint
Starting >>> gtest_vendor
Starting >>> ament_cppcheck
Starting >>> ament_pycodestyle
Finished <<< gtest_vendor [1.83s]
Starting >>> gmock_vendor
Finished <<< gmock_vendor [0.24s]
--- stderr: ament_package
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/colcon_core/executor/__init__.py", line 91, in __call__
rc = await self.task(*args, **kwargs)
File "/usr/lib/python3/dist-packages/colcon_core/task/__init__.py", line 93, in __call__
return await task_method(*args, **kwargs)
File "/usr/lib/python3/dist-packages/colcon_ros/task/ament_python/build.py", line 105, in build
return await extension.build(additional_hooks=additional_hooks)
File "/usr/lib/python3/dist-packages/colcon_core/task/python/build.py", line 59, in build
available_commands = await self._get_available_commands(
File "/usr/lib/python3/dist-packages/colcon_core/task/python/build.py", line 142, in _get_available_commands
output = await check_output(
File "/usr/lib/python3/dist-packages/colcon_core/subprocess.py", line 128, in check_output
assert not rc, f'Expected {args} to pass: {stderr_data}'
AssertionError: Expected ['/usr/bin/python3', 'setup.py', '--help-commands'] to pass: Traceback (most recent call last):
File "setup.py", line 6, in <module>
setup(
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/__init__.py", line 87, in setup
return distutils.core.setup(**attrs)
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 164, in setup
ok = dist.parse_command_line()
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 471, in parse_command_line
if self.handle_display_options(option_order):
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/dist.py", line 1185, in handle_display_options
return _Distribution.handle_display_options(self, option_order)
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 685, in handle_display_options
self.print_commands()
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/dist.py", line 962, in print_commands
cmdclass = ep.load()
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 194, in load
module = import_module(match.group('module'))
File "/usr/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 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/fabi/.local/lib/python3.8/site-packages/sphinx/setup_command.py", line 20, in <module>
from sphinx.application import Sphinx
File "/home/fabi/.local/lib/python3.8/site-packages/sphinx/application.py", line 43, in <module>
from sphinx.registry import SphinxComponentRegistry
File "/home/fabi/.local/lib/python3.8/site-packages/sphinx/registry.py", line 24, in <module>
from sphinx.builders import Builder
File "/home/fabi/.local/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 26, in <module>
from sphinx.util import import_object, logging, progress_message, rst, status_iterator
File "/home/fabi/.local/lib/python3.8/site-packages/sphinx/util/rst.py", line 21, in <module>
from jinja2 import Environment, environmentfilter
ImportError: cannot import name 'environmentfilter' from 'jinja2' (/home/fabi/.local/lib/python3.8/site-packages/jinja2/__init__.py)
---
Failed <<< ament_package [2.52s, exited with code 1]
Aborted <<< ament_pycodestyle [2.46s]
Aborted <<< ament_lint [2.52s]
Aborted <<< ament_cppcheck [2.51s]
Summary: 2 packages finished [2.99s]
1 package failed: ament_package
3 packages aborted: ament_cppcheck ament_lint ament_pycodestyle
1 package had stderr output: ament_package
54 packages not processed
Expected ['/usr/bin/python3', 'setup.py', '--help-commands'] to pass: Traceback (most recent call last):
File "setup.py", line 6, in <module>
setup(
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/__init__.py", line 87, in setup
return distutils.core.setup(**attrs)
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 164, in setup
ok = dist.parse_command_line()
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 471, in parse_command_line
if self.handle_display_options(option_order):
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/dist.py", line 1185, in handle_display_options
return _Distribution.handle_display_options(self, option_order)
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 685, in handle_display_options
self.print_commands()
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/dist.py", line 962, in print_commands
cmdclass = ep.load()
File "/home/fabi/.local/lib/python3.8/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 194, in load
module = import_module(match.group('module'))
File "/usr/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 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/fabi/.local/lib/python3.8/site-packages/sphinx/setup_command.py", line 20, in <module>
from sphinx.application import Sphinx
File "/home/fabi/.local/lib/python3.8/site-packages/sphinx/application.py", line 43, in <module>
from sphinx.registry import SphinxComponentRegistry
File "/home/fabi/.local/lib/python3.8/site-packages/sphinx/registry.py", line 24, in <module>
from sphinx.builders import Builder
File "/home/fabi/.local/lib/python3.8/site-packages/sphinx/builders/__init__.py", line 26, in <module>
from sphinx.util import import_object, logging, progress_message, rst, status_iterator
File "/home/fabi/.local/lib/python3.8/site-packages/sphinx/util/rst.py", line 21, in <module>
from jinja2 import Environment, environmentfilter
ImportError: cannot import name 'environmentfilter' from 'jinja2' (/home/fabi/.local/lib/python3.8/site-packages/jinja2/__init__.py)```
Ok, I found the solution.
I solved it by removing the jinja2 version I had installed and installing an older version (3.0).

Superset exporting and importing the Dashboards using CLI (for versioning control)

Goal: My goal is to export the all the dashboards from the superset so that I can save them as backup and also make sure that I can import them.
Existing setup: I am cloning superset from git and using docker-compose -f docker-compose-non-dev.yml up
to setup and run the superset (following this documentation)
Issue:
Using superset CLI: I am using this documentation
to connect to the existing docker image on which superset is running and then running superset export-dashboards but it throws the following error:
Loaded your LOCAL configuration at [/app/docker/pythonpath_dev/superset_config.py]
logging was configured successfully
2021-10-20 06:54:49,727:INFO:superset.utils.logging_configurator:logging was configured successfully
2021-10-20 06:54:49,732:INFO:root:Configured event logger of type <class 'superset.utils.log.DBEventLogger'>
/usr/local/lib/python3.8/site-packages/flask_caching/__init__.py:201: UserWarning: Flask-Caching: CACHE_TYPE is set to null, caching is effectively disabled.
warnings.warn(
Starting export
2021-10-20 06:54:50,962:INFO:superset.utils.dashboard_import_export:Starting export
Traceback (most recent call last):
File "/usr/local/bin/superset", line 33, in <module>
sys.exit(load_entry_point('apache-superset', 'console_scripts', 'superset')())
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 586, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 426, in decorator
return __ctx.invoke(f, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/flask/cli.py", line 426, in decorator
return __ctx.invoke(f, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/app/superset/cli.py", line 413, in export_dashboards
data = dashboard_import_export.export_dashboards(db.session)
File "/app/superset/utils/dashboard_import_export.py", line 33, in export_dashboards
data = Dashboard.export_dashboards(dashboard_ids)
File "/app/superset/models/dashboard.py", line 385, in export_dashboards
json_metadata = json.loads(dashboard.json_metadata)
File "/usr/local/lib/python3.8/json/__init__.py", line 341, in loads
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not NoneType
Kindly help me debug, I have also changed the "VERSIONED_EXPORT": True

Problem with rosdep when trying to check for dependencies

I am trying to run the following rosdep command to check for missing dependencies in my ROS2 package:
rosdep install -i --from-path src --rosdistro galactic -y
However, when I try to run this line of code in my terminal, I get the following error:
Traceback (most recent call last):
File "/usr/bin/rosdep", line 33, in <module>
sys.exit(load_entry_point('rosdep==0.21.0', 'console_scripts', 'rosdep')())
File "/usr/bin/rosdep", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/lib/python3.8/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/usr/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 "/usr/lib/python3/dist-packages/rosdep2/__init__.py", line 45, in <module>
from .lookup import RosdepDefinition, RosdepView, RosdepLookup, \
File "/usr/lib/python3/dist-packages/rosdep2/lookup.py", line 44, in <module>
from .sources_list import SourcesListLoader
File "/usr/lib/python3/dist-packages/rosdep2/sources_list.py", line 50, in <module>
from .gbpdistro_support import get_gbprepo_as_rosdep_data, download_gbpdistro_as_rosdep_data
File "/usr/lib/python3/dist-packages/rosdep2/gbpdistro_support.py", line 20, in <module>
from .platforms.redhat import YUM_INSTALLER
File "/usr/lib/python3/dist-packages/rosdep2/platforms/redhat.py", line 34, in <module>
from rospkg.os_detect import (
ImportError: cannot import name 'OS_ALMALINUX' from 'rospkg.os_detect' (/usr/local/lib/python3.8/dist-packages/rospkg-1.2.8-py3.8.egg/rospkg/os_detect.py)
I tried to search on the forums to see if anyone had an error with importing 'OS_ALMALINUX' but I couldn't find any similar case.
Does anyone know how I can fix this issue?
Thank you
For me, the solution was to remove rospkg from pip (pip uninstall rospkg) and use rospkg installed from apt instead (sudo apt install python3-rospkg). It seems that the incorrect version was installed through pip or that there was some conflict between the pip and apt versions.

Build gerrit events-log plugin

I am trying to build gerrit events-log plugin via Buck build, but its failing with error:
root#monkey:/tmp/events-log# buck build plugin
[-] PROCESSING BUCK FILES...FINISHED 0.3s [100%]
[+] DOWNLOADING... (0.00 B/S, TOTAL: 0.00 B, 0 Artifacts)
[+] BUILDING...0.2s [19%] (3/19 JOBS, 0 UPDATED, 0.0% CACHE MISS)
|=> //lib/commons:dbcp__download_bin... 0.1s (running genrule[0.0s])
Traceback (most recent call last):
File ".bootstrap/_pex/pex.py", line 320, in execute
File ".bootstrap/_pex/pex.py", line 253, in _wrap_coverage
File ".bootstrap/_pex/pex.py", line 285, in _wrap_profiling
File ".bootstrap/_pex/pex.py", line 363, in _execute
File ".bootstrap/_pex/pex.py", line 421, in execute_entry
File ".bootstrap/_pex/pex.py", line 426, in execute_module
File "/usr/lib/python2.7/runpy.py", line 180, in run_module
fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "bucklets/tools/download_file.py", line 198, in <module>
File "/usr/lib/python2.7/subprocess.py", line 535, in check_call
retcode = call(*popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Can somebody please tell how to fix it?
Thanks
If you haven't already figured this out, ensure that 'zip' is installed and in your $PATH.
github issue for similar failure in a different plugin

Resources