importing pyjnius in python shell gives KeyError - python

I have installed pyjnius module in python 2.7.12. I don't really remember how did I installed it.
I have a simple script:
#!/usr/bin/python
from jnius import autoclass
# do something here
I can run this without getting any error but when I try to write my code in the python shell, it gives an error.
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from jnius import autoclass
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/jnius/__init__.py", line 13, in <module>
from .reflect import * # noqa
File "/usr/local/lib/python2.7/dist-packages/jnius/reflect.py", line 14, in <module>
class Class(with_metaclass(MetaJavaClass, JavaClass)):
File "/usr/local/lib/python2.7/dist-packages/six.py", line 827, in __new__
return meta(name, bases, d)
File "jnius/jnius_export_class.pxi", line 43, in jnius.MetaJavaClass.__new__ (jnius/jnius.c:18031)
File "jnius/jnius_export_class.pxi", line 65, in jnius.MetaJavaClass.resolve_class (jnius/jnius.c:18439)
File "jnius/jnius_env.pxi", line 11, in jnius.get_jnienv (jnius/jnius.c:3710)
File "jnius/jnius_jvm_dlopen.pxi", line 90, in jnius.get_platform_jnienv (jnius/jnius.c:3641)
File "jnius/jnius_jvm_dlopen.pxi", line 45, in jnius.create_jnienv (jnius/jnius.c:2965)
File "/usr/lib/python2.7/UserDict.py", line 40, in __getitem__
raise KeyError(key)
KeyError: 'JAVA_HOME'
Is there something wrong with my pyjnius?
I tried to uninstall my current pyjnius module using:
sudo apt-get purge pyjnius
But it says:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package pyjnius
I would appreciate any hints to my problem.

Related

Is there any way to fix azure cli import pyparsing error on mac?

I'm trying to run azure CLI after reinstalling it I'm getting:
$ az
Traceback (most recent call last):
File "/usr/local/Cellar/python#3.8/3.8.11/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 185, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/local/Cellar/python#3.8/3.8.11/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/azure/__init__.py", line 1, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/pkg_resources/__init__.py", line 78, in <module>
__import__('pkg_resources.extern.packaging.requirements')
File "/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
File "/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/pkg_resources/extern/__init__.py", line 52, in create_module
return self.load_module(spec.name)
File "/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/pkg_resources/extern/__init__.py", line 44, in load_module
raise ImportError(
ImportError: The 'pyparsing' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.
I checked the python binary path and I saw I already have this package.
Found the issue.
One of the sub-packages that called in the pyparsing package was called to a local folder script that has the same name. and as a result the import faild.
$ /usr/local/Cellar/azure-cli/2.25.0/libexec/bin/python
Python 3.8.11 (default, Jun 29 2021, 03:08:07)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyparsing
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/azure-cli/2.25.0/libexec/lib/python3.8/site-packages/pyparsing.py", line 104, in <module>
import copy
File "/Users/shprayev/copy.py", line 4, in <module>
from pymongo import MongoClient
ModuleNotFoundError: No module named 'pymongo'
So pyparsing imports copy and I had copy.py in my path.
after rename the script it worked

Problem trying to install Naoqi Python-SDK: "SystemError: dynamic module not initialized properly"

I saw someone was answering the same question here: Python for Naoqi (dynamic module not initialized properly), but I follow the answers in the page, still cannot get it working. Could someone advice how to proceed?
Using Python 2.7.10 doesn't help.
Under Anaconda Python 2.7.10:
Python 2.7.10 |Continuum Analytics, Inc.| (default, Oct 19 2015, 18:31:17)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import naoqi
Traceback (most recent call last):
File "/opt/anaconda3/envs/pepper_test2/lib/python2.7/site.py", line 557, in <module>
main()
File "/opt/anaconda3/envs/pepper_test2/lib/python2.7/site.py", line 539, in main
known_paths = addusersitepackages(known_paths)
File "/opt/anaconda3/envs/pepper_test2/lib/python2.7/site.py", line 275, in addusersitepackages
user_site = getusersitepackages()
File "/opt/anaconda3/envs/pepper_test2/lib/python2.7/site.py", line 250, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/opt/anaconda3/envs/pepper_test2/lib/python2.7/site.py", line 240, in getuserbase
USER_BASE = get_config_var('userbase')
File "/opt/anaconda3/envs/pepper_test2/lib/python2.7/sysconfig.py", line 520, in get_config_var
return get_config_vars().get(name)
File "/opt/anaconda3/envs/pepper_test2/lib/python2.7/sysconfig.py", line 453, in get_config_vars
import re
File "/opt/anaconda3/envs/pepper_test2/lib/python2.7/re.py", line 108, in <module>
import _locale
SystemError: dynamic module not initialized properly
Under Mac System Python 2.7.10:
Python 2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import naoqi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/cchan/Documents/technical/python_sdk/pynaoqi-python2.7-2.5.5.5-mac64/lib/python2.7/site-packages/naoqi.py", line 9, in <module>
import qi
File "/Users/cchan/Documents/technical/python_sdk/pynaoqi-python2.7-2.5.5.5-mac64/lib/python2.7/site-packages/qi/__init__.py", line 88, in <module>
from _qi import Application as _Application
ImportError: dlopen(/Users/cchan/Documents/technical/python_sdk/pynaoqi-python2.7-2.5.5.5-mac64/lib/python2.7/site-packages/_qi.so, 2): Library not loaded: /Library/Frameworks/Python.framework/Versions/2.7/Python
Referenced from: /Users/cchan/Documents/technical/python_sdk/pynaoqi-python2.7-2.5.5.5-mac64/lib/python2.7/site-packages/_qi.so
Reason: image not found
I have also added the PYTHONPATH in my ~/.bash_profile:
export PYTHONPATH="$PYTHONPATH:/Users/cchan/Documents/technical/python_sdk/pynaoqi-python2.7-2.5.5.5-mac64/lib/python2.7/site-packages"
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/Users/cchan/Documents/technical/python_sdk/pynaoqi-python2.7-2.5.5.5-mac64/lib"
export DYLD_FRAMEWORK_PATH="$DYLD_FRAMEWORK_PATH:/Users/cchan/Documents/technical/python_sdk/pynaoqi-python2.7-2.5.5.5-mac64"
Could someone advise what to do? Thanks in advance!
I found out the problem. The system Python 2.7.10 came with the Mac OS X doesn't work. I have to download the Python 2.7.10 from the Python website and install that in order to have it work: Python Release Website
This answer was original posted by Calvin in question see revision 2

ImportError: libcudnn.so.5: cannot open shared object file: No such file or directory, Python 2.7 with Tensorflow-gpu

Trying to enable tensorflow-gpu over python2.7 after installing Nvidia Quadro M4000. I got the below error message:
Strange thing is that it's complaining about libcudnn.so.5, but I have libcudnn.so.7 in /usr/local/cuda/lib64
Thanks for any suggestions!
~$ python
Python 2.7.13 |Anaconda 4.3.0 (64-bit)| (default, Dec 20 2016, 23:09:15)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
import tensorflow as tf
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/google/home/hjchai/anaconda2/lib/python2.7/site-packages/tensorflow/init.py", line 24, in
from tensorflow.python import *
File "/usr/local/google/home/hjchai/anaconda2/lib/python2.7/site-packages/tensorflow/python/init.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "/usr/local/google/home/hjchai/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/google/home/hjchai/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in
from tensorflow.python.pywrap_tensorflow_internal import *
File "/usr/local/google/home/hjchai/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in
_pywrap_tensorflow_internal = swig_import_helper()
File "/usr/local/google/home/hjchai/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
ImportError: libcudnn.so.5: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
Updating with my own solution.
It turns out I installed cudnn7.0 rather than cudnn5.1.
Problem solved after I install the cudnn5.1.
cheers!

boto3 on ubuntu trusty (ImportError: No module named packages.urllib3.exceptions)

I'm having trouble using the vendor-supplied boto3 on Ubuntu Trusty. Has anyone else run into this issue, and if so how did you resolve?
FWIW, boto3 works fine in a venv on the same machine, so I think this is a packaging issue. I need to make boto3 available on 1000+ machines, so using the vendor-supplied package is desirable.
I tried installing lxml, cssselect, and requests manually as described in
How to fix ImportError: No module named packages.urllib3? but that didn't solve the problem.
Thanks,
Jeffrey
vagrant#vagrant-ubuntu-trusty-64:~$ cat /etc/issue
Ubuntu 14.04.3 LTS \n \l
vagrant#vagrant-ubuntu-trusty-64:~$ sudo aptitude install python-boto3
....
vagrant#vagrant-ubuntu-trusty-64:~$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
>>> boto3.__version__
'1.2.2'
>>> boto3.resource('s3')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/boto3/__init__.py", line 87, in resource
return _get_default_session().resource(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/boto3/session.py", line 292, in resource
aws_session_token=aws_session_token, config=config)
File "/usr/lib/python2.7/dist-packages/boto3/session.py", line 200, in client
aws_session_token=aws_session_token, config=config)
File "/usr/lib/python2.7/dist-packages/botocore/session.py", line 796, in create_client
client_config=config, api_version=api_version)
File "/usr/lib/python2.7/dist-packages/botocore/client.py", line 59, in create_client
cls = self._create_client_class(service_name, service_model)
File "/usr/lib/python2.7/dist-packages/botocore/client.py", line 76, in _create_client_class
base_classes=bases)
File "/usr/lib/python2.7/dist-packages/botocore/hooks.py", line 226, in emit
return self._emit(event_name, kwargs)
File "/usr/lib/python2.7/dist-packages/botocore/hooks.py", line 209, in _emit
response = handler(**kwargs)
File "/usr/lib/python2.7/dist-packages/boto3/utils.py", line 59, in _handler
module = import_module(module)
File "/usr/lib/python2.7/dist-packages/boto3/utils.py", line 52, in import_module
__import__(name)
File "/usr/lib/python2.7/dist-packages/boto3/s3/inject.py", line 13, in <module>
from boto3.s3.transfer import S3Transfer
File "/usr/lib/python2.7/dist-packages/boto3/s3/transfer.py", line 138, in <module>
from requests.packages.urllib3.exceptions import ReadTimeoutError
ImportError: No module named packages.urllib3.exceptions
On the same machine, installing boto3 in a venv seems to work fine. (At least I'm able to create a ServiceResource() object.)
vagrant#vagrant-ubuntu-trusty-64:~$ virtualenv venv-boto3
New python executable in venv-boto3/bin/python
Installing setuptools, pip...done.
vagrant#vagrant-ubuntu-trusty-64:~$ source venv-boto3/bin/activate
(venv-boto3)vagrant#vagrant-ubuntu-trusty-64:~$ pip install boto3
Downloading/unpacking boto3
Downloading boto3-1.4.4-py2.py3-none-any.whl (127kB): 127kB downloaded
...
(venv-boto3)vagrant#vagrant-ubuntu-trusty-64:~$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
>>> boto3.__version__
'1.4.4'
>>> boto3.resource('s3')
s3.ServiceResource()

Not able to install requests on cygwin - ImportError: No module named _io

When I try the following command
pip install requests
I am getting the following error
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 343, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2307, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2013, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/lib/python2.7/site-packages/pip-1.4.1-py2.7.egg/pip/__init__.py", line 10, in <module>
from pip.util import get_installed_distributions, get_prog
File "/usr/lib/python2.7/site-packages/pip-1.4.1-py2.7.egg/pip/util.py", line 8, in <module>
import zipfile
File "/usr/lib/python2.7/zipfile.py", line 6, in <module>
import io
File "/usr/lib/python2.7/io.py", line 60, in <module>
import _io
ImportError: No module named _io
But when I tried to check the env using the following command
env python
I could see that it is running from python 2.7 only
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[GCC 4.5.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
So in the interactive command line I tried the following
>>> import _io
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named _io
It is probably because your Anti-Virus program deleted io.py. I just had to reinstall python on cygwin and try installing the program with the Anti-Virus turned off. I successfully installed request this way.
Your pip has broken or conflict with two package installation easy_install vs pip.
1) upgrade or re install with easy_install pip
will solve the problem, if you have other issue with your virtual env due to 14.04 upgrade then look at the question here.similar stackoverflow question

Categories