I have already request lib but getting ImportError: No module named request [duplicate] - request

I am trying to install python SpeechRecognition on my machine.When i am trying to install the package as pip install SpeechRecognition. I am getting the following error.
import json, urllib.request
ImportError: No module named request
And then i referred and installed requests as pip install requests i am i am getting Requirement already satisfied.But still i am unable to install SpeechRecognition.Please let me know what mistake i am doing.Thanks in advance

The SpeechRecognition library requires Python 3.3 or up:
Requirements
[...]
The first software requirement is Python 3.3 or better. This is required to use the library.
and from the Trove classifiers:
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
The urllib.request module is part of the Python 3 standard library; in Python 2 you'd use urllib2 here.

You can do that using Python 2.
Remove request
Make that line: from urllib2 import urlopen
You cannot have request in Python 2, you need to have Python 3 or above.

from #Zzmilanzz's answer I used
try: #python3
from urllib.request import urlopen
except: #python2
from urllib2 import urlopen

Related

Terminal issues error message that no Django module "models" exists, but it is in the directory

I'm a motivated beginner working my way through Python Crash Course. I created a project and an app using Django. I'm unable to get the python manage.py run server command to work. This is the header of the long error message:
"Watching for file changes with StatReloader
Exception in thread Django-main-thread".
The middle includes several lines of "".
At the end, it says "from models import Activity"
"ModuleNotFoundError: No module named 'models''
There IS a module named models in the directory. This is my second exercise using Django, and the program worked earlier. I've searched the net and read everything remotely similar, but have been unable to find a solution. How can I make the program recognize a module that is there?
I think the problem was that the version of pip in the virtual environment was the python 2.7 version instead of the 3.9 version I used to create the project. It had to be upgraded using:
python3 -m pip install --upgrade pip
I also used python3 for the manage.py runserver command instead of just python.

Getting HTTP Client error using the s3 client

Operating system is Ubuntu 16.04
Python version is 3
Installed the AWS CLI using PIP
AWS CLI version is aws-cli/1.16.309 Python/3.6.9 Linux/4.20.17-042017-generic botocore/1.13.45
I set the HMAC creds correctly and type the following in my command line:
ncheaz#thinkburger:~/Projects/drupal-interact$ aws --endpoint-url 'https://control.cloud-object-storage.cloud.ibm.com/v2/endpoints' s3 ls
An HTTP Client raised and unhandled exception: __init__() got an unexpected keyword argument 'ssl_context'
Check your urllib3 version. Upgrading urllib3 to 1.25.11 (latest) solved the problem for me. https://pypi.org/project/urllib3/1.25.11/
You can load the urllib (or urllib3) module by loading it in the Python Interpreter and then checking it's version:
$ python
>>> import urllib
>>> urllib.__version__
'1.17'

Pandas and Numpy Import error when using Apache2, Anaconda and Django

Am getting the following error - Missing required dependencies ['numpy']
Standalone and via Django, without Apache2 integration - the code work likes charm, however things start to fall when used with Apache2. It refuses to import pandas or numpy giving one error after another.
I am using Apache2, libapache2-mod-wsgi-py3, Python 3.5 and Anaconda 2.3.0
Request Method: GET
Request URL: http://127.0.0.1/api/users/0/
Django Version: 1.10.5
Exception Type: ImportError
Exception Value:
Missing required dependencies ['numpy']
Exception Location: /home/fractaluser/anaconda3/lib/python3.4/site-packages/pandas/__init__.py in <module>, line 18
Python Executable: /usr/bin/python3
Python Version: 3.5.2
Python Path:
['/home/fractaluser/anaconda3/lib/python3.4/site-packages',
'/home/fractaluser/anaconda3/lib/python3.4/site-packages/Sphinx-1.3.1-py3.4.egg',
'/home/fractaluser/anaconda3/lib/python3.4/site-packages/setuptools-27.2.0-py3.4.egg',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages',
'/var/www/html/cgmvp']
Server time: Fri, 9 Jun 2017 11:12:37 +0000
You can't force mod_wsgi built with the system Python version to use a Python virtual environment built for a different Python version, nor different Python installation. That is what it appears you are doing. You would need to uninstall mod_wsgi and install it from source code, compiling it against the Anaconda Python distribution. Best to use the pip install method and follow steps to integrate it into existing Apache installation. See:
https://pypi.python.org/pypi/mod_wsgi
Also see the following documentation for setting up a Python virtual environment with mod_wsgi, as it appears you aren't doing that in the recommended way either.
http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
First task though is to reinstall mod_wsgi.
I had the same problem using apache2 with mod_wsgi python 3.6 envinronmet 64, the version numpy used was 1.13, only change the version with previous and worked !!.
pip3 install numpy==1.12

Error with module using Cloud Storage with Python and his tutorial

I'm trying to test Google Cloud Storage to store images (I need it in an app that I'm developing) and I'm following the Bookshelf App tutorial that they have in his webpage.
I'm using python and the problem is that when I execute the requirementes.txt all packages have been installed fine, but when I try execute the code, I see this error:
...sandbox.py", line 948, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named cryptography.hazmat.bindings._openssl
I have been trying hundred of posibles solutions, reinstalling only the cryptography package, trying to use different versions of the same module, and installing other packages that contains it but anything resolved the problem.
The requirements contains this:
Flask==0.10.1
gcloud==0.9.0
gunicorn==19.4.5
oauth2client==1.5.2
Flask-SQLAlchemy==2.1
PyMySQL==0.7.1
Flask-PyMongo==0.4.0
PyMongo==3.2.1
six==1.10.0
I'm sure that it is a simple error but I don't find the way to solve it.
Any help will be welcome. Thanks.
EDIT:
When I try do this with a python program this work fine:
import os
from gcloud import storage
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'key.json'
client = storage.Client(project='xxxxxxx')
bucket = client.get_bucket('yyyyyyy')
f = open('profile.jpg', 'rb')
blob = bucket.blob(f.name)
blob.upload_from_string(f.read(), 'image/jpeg')
url = blob.public_url
print url
Why I don't can use gcloud library without erros in a GAE app?
It seems you're following the bookshelf tutorial, but according to this line in your stacktrace:
...sandbox.py", line 948, in load_module
It hints that you're using dev_appserver.py to run the code. This isn't necessary for Managed VMs/Flexible unless you're using the compat runtime.
If this is the case, the tutorial provides correct instructions:
$ virtualenv env
$ source env/bin/activate
$ pip install -r requirements.txt
$ python main.py
(If this is not the case, please feel free to comment on this with more details about how you're running your application).

Why am I getting: EventError: libraries entries only supported by python27 runtime? when running GAE

I'm running a local development copy of Google AppEngine PHP SDK v1.8.0, with PHP v5.4.3 and Python v2.7, all under Windows 7 64bit.
I have followed instructions from a number of posts both here and elsewhere in order to register Python with my OS and to properly install the Python PIL module.
The last post I found here Unable to find the Python PIL library.Google App Engine. I have therefore added :
libraries:
- name: PIL
version: 1.1.7
to app.yaml.
I now receive the error quoted in the title of this post. If anyone can advise, I would be grateful.
Thankyou.
I think what #Tim was trying to say is that you should change your app.yaml to say "runtime: python27" instead of "runtime: php" since, as the error suggests, the PIL library is only supported by python27, not php.

Resources