How to import Webots controller in a Ros-python script - python-2.7

I want to write a controller in Python and trying to import Webots controller library:
#!/usr/bin/env python
import rospy
from std_msgs.msg import String
from time import sleep
from controller import Robot
and get the error
Traceback (most recent call last):
File "./mine_controller.py", line 6, in <module>
from controller import Robot
File "/snap/webots/current/usr/share/webots/lib/controller/python27/controller.py", line 17, in <module>
_controller = swig_import_helper()
File "/snap/webots/current/usr/share/webots/lib/controller/python27/controller.py", line 16, in swig_import_helper
return importlib.import_module('_controller')
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: libCppController.so: cannot open shared object file: No such file or directory
My environmental variables :
PYTHONPATH=/snap/webots/current/usr/share/webots/lib/controller/python27:/home/boand/workspace_ros/devel/lib/python2.7/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages
LD_LIBRARY_PATH=/home/boand/workspace_ros/devel/lib:/opt/ros/melodic/lib:/snap/webots/current/usr/share/webots/lib

It seems your LD_LIBRARY_PATH is wrong, /snap/webots/current/usr/share/webots/lib should be replaced by /snap/webots/current/usr/share/webots/lib/controller.

Related

Error loading patching payloadfailed to run commands: exit status 156

I'm automating my EC2 instances with Patch Manager and I'm getting this error.
Error loading patching payloadfailed to run commands: exit status 156
The error output logs are these:
/usr/bin/python3
/usr/bin/apt-get
Reading package lists...
Building dependency tree...
Reading state information...
python3-apt is already the newest version (2.3.0ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
Using python binary: 'python3'
Using Python Version: Python 3.10.4
/usr/bin/curl
/usr/bin/wget
05/29/2022 01:11:51 root [INFO]: Downloading payload from https://s3.dualstack.sa-east-1.amazonaws.com/aws-ssm-sa-east-1/patchbaselineoperations/linux/payloads/patch-baseline-operations-1.86.tar.gz
05/29/2022 01:11:52 root [INFO]: Attempting to import entrance file os_selector
05/29/2022 01:11:52 root [ERROR]: Error loading entrance module.
Traceback (most recent call last):
File "/var/log/amazon/ssm/patch-baseline-operations/common_startup_entrance.py", line 154, in execute
entrance_module = __import__(module_name)
File "/var/log/amazon/ssm/patch-baseline-operations/os_selector.py", line 11, in <module>
import common_os_selector_methods
File "/var/log/amazon/ssm/patch-baseline-operations/common_os_selector_methods.py", line 11, in <module>
from patch_common.baseline_override import load_baseline_override
File "/var/log/amazon/ssm/patch-baseline-operations/patch_common/baseline_override.py", line 6, in <module>
from patch_common.downloader import download_file, load_json_file, is_access_denied
File "/var/log/amazon/ssm/patch-baseline-operations/patch_common/downloader.py", line 1, in <module>
import boto3
File "/var/log/amazon/ssm/patch-baseline-operations/boto3/__init__.py", line 16, in <module>
from boto3.session import Session
File "/var/log/amazon/ssm/patch-baseline-operations/boto3/session.py", line 17, in <module>
import botocore.session
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/session.py", line 29, in <module>
import botocore.configloader
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/configloader.py", line 19, in <module>
from botocore.compat import six
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/compat.py", line 25, in <module>
from botocore.exceptions import MD5UnavailableError
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/exceptions.py", line 15, in <module>
from botocore.vendored import requests
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/__init__.py", line 58, in <module>
from . import utils
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/compat.py", line 7, in <module>
from .packages import chardet
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/__init__.py", line 10, in <module>
from .connectionpool import (
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 38, in <module>
from .response import HTTPResponse
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/response.py", line 9, in <module>
from ._collections import HTTPHeaderDict
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/_collections.py", line 1, in <module>
from collections import Mapping, MutableMapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
05/29/2022 01:11:52 root [ERROR]: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
Traceback (most recent call last):
File "/var/log/amazon/ssm/patch-baseline-operations/common_startup_entrance.py", line 154, in execute
entrance_module = __import__(module_name)
File "/var/log/amazon/ssm/patch-baseline-operations/os_selector.py", line 11, in <module>
import common_os_selector_methods
File "/var/log/amazon/ssm/patch-baseline-operations/common_os_selector_methods.py", line 11, in <module>
from patch_common.baseline_override import load_baseline_override
File "/var/log/amazon/ssm/patch-baseline-operations/patch_common/baseline_override.py", line 6, in <module>
from patch_common.downloader import download_file, load_json_file, is_access_denied
File "/var/log/amazon/ssm/patch-baseline-operations/patch_common/downloader.py", line 1, in <module>
import boto3
File "/var/log/amazon/ssm/patch-baseline-operations/boto3/__init__.py", line 16, in <module>
from boto3.session import Session
File "/var/log/amazon/ssm/patch-baseline-operations/boto3/session.py", line 17, in <module>
import botocore.session
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/session.py", line 29, in <module>
import botocore.configloader
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/configloader.py", line 19, in <module>
from botocore.compat import six
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/compat.py", line 25, in <module>
from botocore.exceptions import MD5UnavailableError
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/exceptions.py", line 15, in <module>
from botocore.vendored import requests
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/__init__.py", line 58, in <module>
from . import utils
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/compat.py", line 7, in <module>
from .packages import chardet
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/__init__.py", line 10, in <module>
from .connectionpool import (
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 38, in <module>
from .response import HTTPResponse
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/response.py", line 9, in <module>
from ._collections import HTTPHeaderDict
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/_collections.py", line 1, in <module>
from collections import Mapping, MutableMapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
Does anyone have an idea what it could be?
What's the Ubuntu version being used here?
Looking at the Python version (Python 3.10.4) in the error logs, that target instance appears to be running Ubuntu 22.04, which is not yet supported by Patch Manager.
Below is the link for the supported operating systems in Patch Manager prerequisites documentation:
https://docs.aws.amazon.com/systems-manager/latest/userguide/patch-manager-prerequisites.html

error on execute import django in python3 shell and script

when i want do an import django i get an error
ubuntu 18.04 with a reverse proxy (nginx) and uwsgi (mode emperor actived) in virtual env with python 3.6.3 and latest django 2.2.5
test.py:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
import django
print("test")'
when i run python3 test.py i get :
(venv) :~/testproject/testproject/testproject$ python3.6 test.py
Traceback (most recent call last):
File "test.py", line 3, in <module>
from django.http import HttpResponse
File "/home/lukas/testproject/venv/lib/python3.6/site-packages/django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "/home/lukas/testproject/venv/lib/python3.6/site-packages/django/utils/version.py", line 4, in <module>
import subprocess
File "/usr/lib/python3.6/subprocess.py", line 140, in <module>
import threading
File "/usr/lib/python3.6/threading.py", line 7, in <module>
from traceback import format_exc as _format_exc
File "/usr/lib/python3.6/traceback.py", line 5, in <module>
import linecache
File "/home/lukas/testproject/venv/lib/python3.6/linecache.py", line 11, in <module>
import tokenize
File "/home/lukas/testproject/venv/lib/python3.6/tokenize.py", line 35, in <module>
from token import *
File "/home/lukas/testproject/testproject/testproject/token.py", line 1, in <module>
from django.contrib.auth.tokens import PasswordResetTokenGenerator
File "/home/lukas/testproject/venv/lib/python3.6/site-packages/django/contrib/auth/__init__.py", line 4, in <module>
from django.apps import apps as django_apps
File "/home/lukas/testproject/venv/lib/python3.6/site-packages/django/apps/__init__.py", line 2, in <module>
from .registry import apps
File "/home/lukas/testproject/venv/lib/python3.6/site-packages/django/apps/registry.py", line 426, in <module>
apps = Apps(installed_apps=None)
File "/home/lukas/testproject/venv/lib/python3.6/site-packages/django/apps/registry.py", line 46, in __init__
self.ready_event = threading.Event()
AttributeError: module 'threading' has no attribute 'Event'
i have the same error on python3 shell when i do import django whereas django have been installed with pip3 install and production mode is ok and developement mode with runserver is ok too.
can you help me, i m lost...
Do you have, by any chance, a token module in you django project?
As the python path is modified to prefer local modules rather than other pre-defined modules, the from token import * instruction will import from your module instead of the python lib one.
Try renaming your local modules to avoid collision with builtin python modules.

Getting "Import Error" while running Python Flask Application

The following error is getting while attempting to run a sample Python Flask application.
Traceback (most recent call last):
File "/home/bineeth/Projects/python/xcontent/bin/flask", line 7, in <module>
from flask.cli import main
File "/home/bineeth/Projects/python/xcontent/lib/python3.5/site-packages/flask/__init__.py", line 18, in <module>
from werkzeug.exceptions import abort
File "/home/bineeth/Projects/python/xcontent/lib/python3.5/site-packages/werkzeug/__init__.py", line 152, in <module>
__import__('werkzeug.exceptions')
File "/home/bineeth/Projects/python/xcontent/lib/python3.5/site-packages/werkzeug/exceptions.py", line 66, in <module>
from werkzeug.http import HTTP_STATUS_CODES
File "/home/bineeth/Projects/python/xcontent/lib/python3.5/site-packages/werkzeug/http.py", line 31, in <module>
from werkzeug.datastructures import (# noqa
File "/home/bineeth/Projects/python/xcontent/lib/python3.5/site-packages/werkzeug/datastructures.py", line 24, in <module>
from werkzeug.http import dump_options_header, dump_header, generate_etag, \
ImportError: cannot import name 'dump_options_header'
Following is the source code;
from flask import Flask
app = Flask(__name__)
#app.route('/ping')
def ping():
return {'status':'completed'}
if __name__ == '__main__':
app.run(debug=False)
I am using Python 3 and LiClipse IDE. Also Linux Mint is the Operating System.
Appreciate your valuable help in this regard.

tensorflow import error in python 2.7.6

I have installed tensor flow from tensorflow website. While trying to import tensor flow its showing following error
>>>import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 75, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "/usr/local/lib/python2.7/dist-packages/google/protobuf/__init__.py", line 37, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 36, in <module>
import email.parser
File "/usr/lib/python2.7/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser
File "/usr/lib/python2.7/email/feedparser.py", line 27, in <module>
from email import message
File "/usr/lib/python2.7/email/message.py", line 16, in <module>
import email.charset
File "/usr/lib/python2.7/email/charset.py", line 13, in <module>
import email.base64mime
File "/usr/lib/python2.7/email/base64mime.py", line 40, in <module>
from email.utils import fix_eols
File "/usr/lib/python2.7/email/utils.py", line 28, in <module>
import socket
File "/home/tamarind/socket.py", line 5, in <module>
This module provides socket operations and some related functions.
TypeError: 'module' object is not callable
I think its problem with socket please suggest. Please suggest.
It looks like /home/tamarind/socket.py is taking precedence over the python socket module. Just rename/remove that (or import TensorFlow from a different directory) and it should work. You may need to remove socket.pyc too.

Standalone Django application with pyinstaller on Windows

I need to package a (rather simple) django application into a standalone executable on windows. After some failed attempts with py2exe (I really don't understand why everybody recommends it for django, it seems extremely complicated to set up) I tried pyinstaller. It does package the application without complaining, but if I try to run it using myapp.exe runserver localhost:8000, I am getting the following error:
Traceback (most recent call last):
File "<string>", line 5, in <module>
File "c:\python27\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_
module
exec(bytecode, module.__dict__)
File "...\build\ck\out00-PYZ.pyz\django.test", line 5, in <module>
File "c:\python27\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_
module
exec(bytecode, module.__dict__)
File "...\build\ck\out00-PYZ.pyz\django.test.client", line 21, in <module>
File "c:\python27\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\loader\pyi_importers.py", line 270, in load_
module
exec(bytecode, module.__dict__)
File "...\build\ck\out00-PYZ.pyz\django.db", line 11, in <module>
File "...\build\ck\out00-PYZ.pyz\django.conf", line 52, in __getattr__
File "...\build\ck\out00-PYZ.pyz\django.conf", line 45, in _setup
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must eith
er define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
My manage.py script looks like this:
#!/usr/bin/env python
import os
import sys
import Cookie
import django.test
import HTMLParser
from django.conf import settings
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
Why does it not recognize the environment variable and how can I fix that?
I solved it by importing django.test after the line
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")