error when importing jwcrypto in python2.7 - python-2.7

I am using jwcrypto in python2.7, and here comes a problem.
>>> import jwcrypto
>>> from jwcrypto import jwk, jws
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Lsq\.conda\envs\py27\lib\site-packages\jwcrypto\jwk.py", line 318
raise InvalidJWKType(kty) from e
^
SyntaxError: invalid syntax
I am not familiar with python2.7, and it seems like it is not allowed to use raise from in python2.7.
However, in jwk.py i found several raise from which cause the error above. I installed python2.7 via conda create -n py27 python=2.7, and installed jwcrypto via pip install jwcrypto.
Does anyone know how may this problem be solved?

Uninstall 1.0 version and install 0.9.1 version for jwcrypto in python 2.7.
pip install jwcrypto==0.9.1

Related

how to install the ssl module for python 2.7.17 on opensuse (SLES) 15 SP2?

I have installed OpenSSL and python2-pyOpenSSL-17.5.0-lp152.6.2.noarch.rpm in my SLES machine and still, I am getting the following error:
import ssl inside python CLI
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named ssl
pip install numpy gives the following error:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Can anyone help me with this?
You may need to install libopenssl-devel package

pip: ImportError: No module named retrying

I'm trying to create a new environment and install various 3rd party packages on an Ubuntu machine. After having to install condo (for a matplotlib installation) and gdal, the pip function no longer works. Instead I receive:
Traceback (most recent call last):
File "/media/imagery/ENVIRONMENTS/Project_1/bin/pip", line 7, in <module>
from pip._internal import main
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 14, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/usr/lib/python2.7/dist-packages/pip/utils/__init__.py", line 30, in <module>
from pip._vendor.retrying import retry
ImportError: No module named retrying
I've called pip both in and outside my environment, and still observe the same issue. Also I've tried a pip install --upgrade pip and still retrieve the same Traceback. Any ideas how to resolve this?
As a cheap workaround, export PYTHONPATH=" " seemed to work for now in order to install other packages, but as soon as I need the gdal package, I have to then set PYTHONPATH again.
I had a similar exception and could manage to repair it.
In my case I upgraded Ubuntu 16.04 to Ubuntu 18.04.
I had to re-create the virtualenv. Depending on your choice:
virtualenv .
Or
virtualenv --system-site-packages .

Import Error: No Module named ldap, issues with python-ldap module installation on mac os Serira, python 2.7

Running a simple standalone python script on mac os Sierra. I am getting the following error:
Traceback (most recent call last):
File "user_exists.py", line 4, in <module>
import ldap
ImportError: No module named ldap
I went and tried installing using pip the module, I get the following output:
$sudo -H pip install
Requirement already satisfied: python-ldap in /usr/local /bin/python_ldap-2.4.28-py2.7-macosx-10.12-intel.egg
Requirement already satisfied: setuptools in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from python-ldap)
I tried testing:
$ python -c "import ldap"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named ldap
Please suggest whats the best approach to solve this issue?

Can't import a module in python 2.7 even though pip says it is installed

I've read the many posts on SO regarding using Pillow or Image instead of PIL but I'm still having trouble with this module.
I'm running this on my MBP on 10.9.5.
I used pip to install image 1.5.5 and Pillow 3.4.2. However, when I go to import the module in my script, it keeps saying there's no module of that name.
first.last#localhost:/usr/local/bin> pip freeze | grep Pillow
Pillow==3.4.2
first.last#localhost:/usr/local/bin> pip freeze | grep image
image==1.5.5
first.last#localhost:/usr/local/bin> which pip
/usr/local/bin/pip
first.last#localhost:/usr/local/bin> which python
/usr/local/bin/python
Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import image
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named image
>>> import PIL
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named PIL
>>> import Pillow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Pillow
>>> import pillow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pillow
I checked /Library/Python/2.7/site-packages and it doesn't seem like the .py files are there for pillow or image, even though pip freeze showed that image and Pillow are both installed.
This is the contents of pip is this. Not sure if it gives any clues to why pip thinks the modules are installed but python says it can't find it.
#!/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==9.0.1','console_scripts','pip'
__requires__ = 'pip==9.0.1'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('pip==9.0.1', 'console_scripts', 'pip')()
)
From what I showed in my setup/environment, can anyone point me in a general direction to start fixing this problem? Is any additional information needed to debug this some more?
Since you are working outside of a virtualenv, the user site should be enabled. Use the following commands to find the installed location of image and/or pillow:
pip show -f image | grep Location
pip show -f pillow | grep Location
What you probably want to see is something like:
Location: /Users/<your_username>/.local/lib/python2.7/site-packages
If it's not installing there, then uninstall and pip install again with the --user flag.
Then use the following command to make sure that the results of above will be found in your path:
python -m site
What you want to see in the output is something like
sys.path = [
...
]
USER_BASE: '/Users/<your_username>/.local' (exists)
USER_SITE: '/Users/<your_username>/.local/lib/python2.7/site-packages' (exists)
ENABLE_USER_SITE: True
If the installed location is in your user site, and your user site is enabled, then the import will work.

How to use ssl in python 2.7

I am using python 2.7 and i need secure url with ssl protocol(HTTPS).Can we do this in python 2.7
when i trying to import ssl i m getting the following error
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib64/python2.7/ssl.py", line 60, in
import _ssl # if we can't import it, let the error propagate
ImportError: /usr/lib64/python2.7/lib-dynload/_ssl.so: symbol SSLeay_version, version OPENSSL_1.0.1 not defined in file libcrypto.so.10 with link time reference.
Please help me if anybody know...Thanks in advance
I got Answer
I have re-installed openssl
This is the code i used in terminal
sudo yum install openssl-devel