No module named urllib3 - python

I wrote a script to call an API and ran it successfully last week. This week, it won't run. I get back the following error message:
Traceback (most recent call last):
File "user_audit.py", line 2, in <module>
import requests
File "c:\Python27\lib\site-packages\requests\__init__.py", line 60, in <module>
from .packages.urllib3.exceptions import DependencyWarning
File "c:\Python27\lib\site-packages\requests\packages\__init__.py", line 29, in <module>
import urllib3
ImportError: No module named urllib3
I've confirmed that packages is up to date, tried uninstalling and reinstalling it, but nothing has worked so far. Can someone help?
ADDENDUM
I installed urllib3 as suggested by #MSHossain, but then got another error message. The new message referenced another file that I'd written, which had created a Python compiled file. The other file was using smptlib to attempt to send an email. I don't understand how this would happen, but I deleted the other file and my script ran without any problems. I've accepted the answer below as I was able to pip install urllib3, but it should have already been included in the requests module.

Either urllib3 is not imported or not installed.
To import, use
import urllib3
at the top of the file. To install write:
pip install urllib3
into terminal.
It could be that you did not activate the environment variable correctly.
To activate the environment variable, write
source env/bin/activate
into terminal. Here env is the environment variable name.

pip install urllib3
The reason it broke is that I had installed an incompatible version of urllib3 as a transient dependency of awscli. You'll see such conflicts when you rerun the install.

I solved it by running
pip install --upgrade requests

set you environment by writing source env/bin/activate if env not found write virtualenv env first then source env/bin/activate , then check pip freeze if urllib3 not found there then reinstall urllib3, hope it helps.

I already had it installed. Solved it by running pip install --upgrade urllib3
Hope it helps someone :)

Few minutes back, I faced the same issue. And this was because, I used virtual environment. I believe that due to venv directory, the pip installed might have stopped working.
Fortunately, I have setup downloaded in my directory. I ran the setup and chose the option to repair, and now, everything works fine.

For me in PyCharm I had to put import urllib3 at the top of the file as mentioned earlier then PyCharm gave the option to import. Even after installing it with pip

Reinstalling urllib3 solves my problem. Run:
pip uninstall urllib3
pip install urllib3

For the sake of completness. It means the python installation you are using does not have the package installed, be sure you are using the same python installation as the one where you are installing the package.
For me what was happening is that I had a virtual environment made with pyenv, even when the virtual environment had the package installed and in its latest version, it was not found because somehow the underlaying python install was used and not the one where I had the urllib3 installed.
Solution: Use the absolute path to the python binary:
/home/[username]/.pyenv/versions/[envname]/bin/python python-script.py

Related

Requests module for python not being recognized

I am on a Mac.
I installed the requests module to do some web scraping but whenever I run the file it is telling me that it doesn't recognize the requests module. I then checked if the module is installed and it was. I've attached a screenshot.
And here is the error message
File "scraper.py", line 1, in <module>
import requests
ImportError: No module named requests
The issue is with the different versions of Python I have. Mac ships with 2.7 by defualt and even though I installed the requests module it was installed for the default python version.
So what I did was
Installed the latest Python version
Changed the default Interpreter Path in Vscode . Here is the official Vscode guide https://code.visualstudio.com/docs/python/environments
And finally installed requests for Python 3 using this command in the terminal
sudo python3 -m pip install requests
You may need to update your pip too
pip install --upgrade pip
I still think I need to manage the Python environments better but that is for another time.

PYPY venv pip ERROR: ModuleNotFoundError: No module named 'pip._vendor.six'

I created venv according to pypy install site:
System-Product-Name:~# virtualenv -p "/home/x/pypy3.8-v7.3.7-linux64/bin/pypy" ve
created virtual environment PyPy3.8.12.final.0-64 in 102ms
Success. Following step 2 (activation) worked as well... and using:
$python
opens pypy same as using ./pypy, which is as intended.
However after this point nothing really works, it's an error fiesta and I can't install packages nowhere as well, nothing works, might be that the installation is damaged but I would love to understand what the nature of the most prevalent of the errors:
what I’m trying to run on PYPY requires web3:
(ve) root#x-System-Product-Name:/home/x/Desktop# python ll.py
Traceback (most recent call last): File "ll.py", line 4, in <module>
from web3 import
Web3ModuleNotFoundError: No module named 'web3'(ve)
when I try to install it even though it’s there - it’s like undetected, or I’m doing something wrong… anyways, I try to install web3 in various console directories:
ModuleNotFoundError: No module named 'pip._vendor.six'
This error pops up, sometimes after long, web3-unrelated Traceback logs.
I tried installing this peculiar package and it gives a long traceback and then:
ModuleNotFoundError: No module named 'pip._vendor.six'
Same error. Basically everything PYPY related is stuck in an error loop with this vendor_six module, whenever I try to install something from pip. Some of the similar problems on the Internet (never found any PYPY problem with this though) suggest pip installation to be damaged.
What is the reason and nature of this error?
How can I solve it? I’ve never been a fan of reinstalling anything as it doesn’t incentivize thorough understanding of the underlying issues, however, I might have to?
Edit: On GitHub there seems to be a long thread about that issue, here: https://github.com/pypa/pipenv/issues/4804 ;however contributors haven’t reached a final conclusion, some - found individually working solutions:
some said installing pyenv helps
or pipenv
or having proper versions of those, either younger versions, or corresponding
some said it’s a purely Debian related issue impossible to replicate on MacOS
I tried installing pyenv and pipenv, running venv after, still outputs the same error though…
Please use the venv module provided with python
pypy3 -m venv /tmp/venv
source /tmp/venv/bin/activate
The version of virtualenv provided with your linux distro does not know about pypy3.8, since pypy3.8 changed the file layout and that version of virtualenv shipped long before pypy3.8 was released.
Got these ModuleNotFoundError: No module named 'pip._vendor.six' errors while getting Django project running on Ubuntu 20.04 LTS using pipenv while it was running fine on MacOS and Debian 11 server. pipenv sync --dev command and any pip install and pip uninstall commands ran inside pipenv shell were failing with the same error.
Tried multiple fixes including some from this same Github Issue page as OP with no luck. Finally got it working from a suggestion on a somewhat related Ubuntu pipenv bug report page https://bugs.launchpad.net/ubuntu/+source/pipenv/+bug/1885609 which was to remove "dangling virtualenv from previous version" with command:
rm -rf ~/.local/share/virtualenvs
Not completely sure how it worked, but it did. pipenv sync --dev runs without errors and Django project runs. Will update if I manage to understand this better.
Try reinstalling pypy's pip3, as suggested by https://stackoverflow.com/a/51166161/473899 .
curl -sS https://bootstrap.pypa.io/get-pip.py | pypy3
I only have experience with a CPython virtualenv, but I had the exact same ModuleNotFoundError: No module named 'pip._vendor.six', and this solved it. Hopefully it'll work with PyPy, too.
After install python by pyenv and then create a new virtual environment by pipenv in Ubuntu 20.04, after enter the new environment and run the command pipenv install packages to install package, I also meet the problem.
I solved this problem by reinstall pip:
curl -LJO https://raw.githubusercontent.com/Thesoul20/daily-work/main/get-pip.py
unset all_proxy && unset ALL_PROXY
python get-pip.py --force-reinstall
Firstly, download the get_pip.py and then forbidden all the proxy in my computer to make sure the last command can success run. After that, you can successful install package by pipenv.

Python3 module not found error after installation with pip3

I have been stuck on a module not found error of python3.
I have a VM on Microsoft Azure, a Centos 7. Then I installed python3 and pip3, and some packages I needed. But there’s one package that I just couldn’t find after I installed it
sudo pip3 install --user stockstats
But whenever i wanted to run a python script using this package, there’s
ModuleNotFoundError: No module named 'stockstats'
What I tried:
pip3 show stockstats
As I really want to see where it was installed. It shows nothing. What it is supposed to do is like this:
Name: openpyxl
Version: 3.0.7
Summary: A Python library to read/write Excel 2010 xlsx/xlsm files
Home-page: https://openpyxl.readthedocs.io
Author: See AUTHORS
Author-email: charlie.clark#clark-consulting.eu
License: MIT
Location: /usr/local/lib/python3.6/site-packages
…
Then I guess it might be something wrong with the installed path, so I uninstalled the package, and then did
sudo pip3 install stockstats --install-option="--prefix=/usr/local/lib"
(I am just guessing if openpyxl is installed there then stockstats should be there too, as python imported openpyxl successfully)
That didn’t work as well, the error still persists.
*I didn’t use any package manager other than pip3.
** some irregularities occurred when I was trying to use python3(see this post). It was resolved, but I am not sure if the error in this post is related to that.
Any help or hint would be appreciated ;)
Thanks all for the prompt reply.
After Guo Lei’s comment, I tried downloading the tar ball for this package and installing it myself without pip, which eventually told me what exactly happened: a module named int-date, required by stockstats, was not installed in the python library directory. After I installed it in the proper directory, the issue is resolved.
As Danila Vershinin and phd had pointed out, I really shouldn’t run pip as root, and that is the source of issue(curiously, however, that only one particular module required by stockstats is installed in /root/.local/lib/. All others are in the right place, maybe I added the prefix flag without remembering it...?)
Still, I am not sure, I ran pip using sudo because I received permission denied errors repeatedly — so should I use something like sudo --user? Or sth else?
This works for me.
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple stockstats
or
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip install stockstats
You can visit This website for Installing pip in centos 7 Pip Install In Centos 7
for maybe some errors in installing pip.
reinstall python.
check that the module name is correctly typed
install stockstats in pip like "pip install stockstats" (getten from pypi.com)

I have installed the package from github but when importing module name not found

I'm trying to use this github repo!
but as soon as I import the package: from pykernels.basic import RBF
the following error is displayed:
ModuleNotFoundError: No module named 'basic'
I have double checked everything given my understanding of python, packages and how anaconda works but I don't know very much. The site-packages are in the path, the evn has the package and the init seems to be alright. I am really lost, if someone could tell me what I'm doing wrong or what else might be done to resolve this? Thank you!
for installation:
pip install git+https://github.com/gmum/pykernels#egg=pykernels
If you have installed both anaconda and original python, you will have two pip installed in your computer. The original python will have it's pip in \Python37\Scripts, and anaconda will have it's in \Users\admin\Anaconda3\Scripts. Your problem is that you used pip that is in \Python37\Scripts, the original pip. The original pip will install into the original python site-packages, not Anaconda's site-packages.
The solution is to make sure you're using Anaconda's pip when installing packages for use with Anaconda.

pip installed module doesn't found - macOS

I installed a Python module using pip. When I tried to import it, I got this error:
Traceback (most recent call last):
File "Untitled.py", line 1, in <module>
import watson_developer_cloud
ModuleNotFoundError: No module named 'watson_developer_cloud'
What can I do to fix this?
I am using macOS Mojave 10.14.2 (beta), pip 10.0.1 (I also tried to upgrade it to 18.1, but after the install the version stayed the same).
You probably installed it with sudo, so it's not accessible when you run the script without sudo. Anyhow, it's really messy to install modules directly. And it's dangerous to install modules to systems python.
Install a brew version of python and pip. then create a virtualenv and install your packages in it. It's much safer and portable.
Read this answer No module named 'pafy'
Please don't run the script as sudo to make it work, especially if you are not the one who wrote it. Use a virtualenv instead.

Categories