ModuleNotFoundError: No module named 'urllib3.exceptions'; 'urllib3' is not a package - python

I'm using the following code to get data from a REST API:
import requests
import json
key = "my service key"
api = "http://api.data.go.kr/openapi/pblprfr-event-info-std?serviceKey=", key, "&s_page=1&s_list=100&type=json"
r = requests.get(api)
data = json.loads(r.text)
print(data["행사명"])
This code produces the following error:
File "sel2.py", line 1, in <module>
import requests
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/init.py", line 46, in <module>
from .exceptions import RequestsDependencyWarning
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/exceptions.py", line 9, in <module>
from urllib3.exceptions import HTTPError as BaseHTTPError
ModuleNotFoundError: No module named 'urllib3.exceptions'; 'urllib3' is not a package
Any ideas what the problem can be?

Most likely something got corrupted in your requests installation or it's dependencies. The following fixed the issue, for me:
# Yeah, do them one-at-a-time, in case of errors:
pip uninstall urllib3
pip install --no-cache-dir -U urllib3
pip uninstall chardet
pip install --no-cache-dir -U chardet

Related

No module named certifi

When executing python3 (Python 3.6.8) script on a local directory, it works well, but when running sbatch job in slurm, complains about certifi.
python3 -m pip install certifi
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: certifi in /usr/local/lib/python3.6/site-packages (2020.12.5)
After adding to the python code this:
import sys
import os
sys.path.append(os.getcwd())
or this:
import sys
import os
module_path = os.path.abspath(os.getcwd())
if module_path not in sys.path:
sys.path.append(module_path)
the same error occurs. It seems that certifi is installed.
pip show certifi
Name: certifi
Version: 2020.12.5
Summary: Python package for providing Mozilla's CA Bundle.
Home-page: https://certifiio.readthedocs.io/en/latest/
Author: Kenneth Reitz
Author-email: me#kennethreitz.com
License: MPL-2.0
Location: /usr/local/lib/python3.6/site-packages
Requires:
Required-by: requests
The error after running python code (without having the line 'import certifi' in python code):
Traceback (most recent call last):
File "/home/username/test/test.py", line 19, in <module>
from textattack.augmentation import WordNetAugmenter, EmbeddingAugmenter, EasyDataAugmenter, CharSwapAugmenter
File "/home/username/.local/lib/python3.6/site-packages/textattack/__init__.py", line 12, in <module>
from . import (
File "/home/username/.local/lib/python3.6/site-packages/textattack/attack_recipes/__init__.py", line 21, in <module>
from .attack_recipe import AttackRecipe
File "/home/username/.local/lib/python3.6/site-packages/textattack/attack_recipes/attack_recipe.py", line 9, in <module>
from textattack.shared import Attack
File "/home/username/.local/lib/python3.6/site-packages/textattack/shared/__init__.py", line 11, in <module>
from . import utils
File "/home/username/.local/lib/python3.6/site-packages/textattack/shared/utils/__init__.py", line 1, in <module>
from .install import *
File "/home/username/.local/lib/python3.6/site-packages/textattack/shared/utils/install.py", line 9, in <module>
import requests
File "/home/username/.local/lib/python3.6/site-packages/requests/__init__.py", line 118, in <module>
from . import utils
File "/home/username/.local/lib/python3.6/site-packages/requests/utils.py", line 25, in <module>
from . import certs
File "/home/username/.local/lib/python3.6/site-packages/requests/certs.py", line 15, in <module>
from certifi import where
ModuleNotFoundError: No module named 'certifi'
The error (with having the line 'import certifi' in python code):
Traceback (most recent call last):
File "/home/username/projecttest_LR_attack/LR_attack.py", line 17, in <module>
import certifi
ModuleNotFoundError: No module named 'certifi'
What could be the solution to the issue?
for anyone on MacOS and already ran pip install certifi and still doesn't work
Go to your applications folder > find your python version folder -> double click on the file Install Certificates.command inside the python folder to install the certificate.
wait for it to complete the installation
After that, you can try running your code with requests package again
Are the same modules installed on the compute nodes as locally? You may need to check with the Slurm admins.
This could mean that /usr/local/lib/python3.6/site-packages/ is not your PYTHONPATH environment variable that sbatch job in slurm has access to. You can either add it or append it during runtime:
import sys
sys.path.append('/usr/local/lib/python3.6/site-packages/')
pip install certifi
Try this command on the CLI

Requests module not found

I'm trying to run my python code with the the requests module.
This is the code I use:
import requests
res = requests.get("https://www.goodreads.com/book/review_counts.json", params={"key": "rhcFvMg9fxSBPoN4TCb7hQ", "isbns": "9781632168146"})
print(res.json())
The following is the error that shows up:
Traceback (most recent call last):
File "/Users/jonathankent/Downloads/project1/test.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
If anyone knows what could be causing this or what I could do to solve it I would be very appreciative.
requests module is not part of python built-in libraries so you have to install it yourself from the command line using pip:
pip install requests
if you are on MacOS try pip3 install requests

ImportError: No module named api_core.exceptions

I wanted to run a google.cloud.storage dependency to my project so I tried to install this dependency with
sudo pip install --upgrade google-api-python-client
Running the above command, we installed all the required packages in the apache airflow dist-packages directory ex:- /usr/local/python2.7/dist-packages/
When i imported libraries into my project using the below code.
from airflow.contrib.operators.mysql_to_gcs import MySqlToGoogleCloudStorageOperator
running the project on Python, i am getting the error ImportError: No module named api_core.exceptions
here is the trace
#python mysql_to_gcs.py
[2019-04-30 06:45:09,668] {settings.py:182} INFO - settings.configure_orm(): Using pool settings. pool_size=5, pool_recycle=1800, pid=15440
Traceback (most recent call last):
File "mysql_to_gcs.py", line 2, in <module>
from airflow.contrib.operators.mysql_to_gcs import MySqlToGoogleCloudStorageOperator
File "/usr/local/lib/python2.7/dist-packages/airflow/contrib/operators/mysql_to_gcs.py", line 25, in <module>
from airflow.contrib.hooks.gcs_hook import GoogleCloudStorageHook
File "/usr/local/lib/python2.7/dist-packages/airflow/contrib/hooks/gcs_hook.py", line 25, in <module>
from airflow.contrib.hooks.gcp_api_base_hook import GoogleCloudBaseHook
File "/usr/local/lib/python2.7/dist-packages/airflow/contrib/hooks/gcp_api_base_hook.py", line 30, in <module>
from google.api_core.exceptions import GoogleAPICallError, AlreadyExists, RetryError
ImportError: No module named api_core.exceptions
Instead of --upgrade google-api-python-client Just reinstall api-core using
pip install dialogflow
Upgrade has some weird problems which does not update api-core.

boto3 cannot import name copy

I installed boto3 few weeks ago and all worked fine until now
tried to reinstall pip, reinstall boto3,reinstall aws cli, update machine (yum update) but nothing helped
File "./get_reports.py", line 4, in <module>
import boto3
File "/usr/lib/python2.7/site-packages/boto3/__init__.py", line 16, in <module>
from boto3.session import Session
File "/usr/lib/python2.7/site-packages/boto3/session.py", line 17, in <module>
import botocore.session
File "/usr/lib/python2.7/site-packages/botocore/session.py", line 25, in <module>
import botocore.configloader
File "/usr/lib/python2.7/site-packages/botocore/configloader.py", line 19, in <module>
from botocore.compat import six
File "/usr/lib/python2.7/site-packages/botocore/compat.py", line 172, in <module>
import xml.etree.cElementTree
File "/usr/lib64/python2.7/xml/etree/cElementTree.py", line 3, in <module>
from _elementtree import *
File "<string>", line 1, in <module>
ImportError: cannot import name copy
aws --version
aws-cli/1.15.3 Python/2.7.5 Linux/3.10.0-693.17.1.el7.x86_64 botocore/1.10.3
Same error when using botocore
code:
#!/usr/bin/env python
import boto3
import json
import csv
client = boto3.client('iam')
response = client.get_account_authorization_details(
)
Your version of boto3 is probably not the same as botocore
try running
pip freeze| grep boto
If the versions are different run
pip install --upgrade botocore
pip install --upgrade boto3
By any chance do you have a copy.py file in your current directory ? Try renaming it, if that's the case

No module named ouathlib.common

I downloaded the and installed the twitter wrapper for python from:
https://python-twitter.googlecode.com/files/python-twitter-1.1.tar.gz
This is all i have in my code now:
import simplejson
import httplib2
import twitter
This is the error i get:
Traceback (most recent call last):
File "C:\Python27\Scripts\tweets.py", line 3, in <module>
import twitter
File "build\bdist.win-amd64\egg\twitter.py", line 38, in <module>
File "C:\Python27\lib\site-packages\requests_oauthlib-0.4.0-py2.7.egg\requests_oauthlib\__init__.py", line 1, in <module>
from .oauth1_auth import OAuth1
File "C:\Python27\lib\site-packages\requests_oauthlib-0.4.0-py2.7.egg\requests_oauthlib\oauth1_auth.py", line 3, in <module>
from oauthlib.common import extract_params
ImportError: No module named oauthlib.common
Which module can i install to stop this error?
https://github.com/idan/oauthlib
Try to install oauthlib to fix the error.
https://github.com/idan/oauthlib
Try to install oauthlib to fix the
error. answered Oct 11 at 12:32 by xiaowl
The above worked for me. I was installing python-twitter and its dependencies in a web2py application /modules subdirectory and was getting a similar error. I installed oauthlib from the above link and all is happy.
Thanks, Xiaowl.

Categories

Resources