The library's setup.py
imports the library to get the version for inclusion in the setup()
function call...
import os
from setuptools
import setup
from ssh_import_id
import __version__
... and the library tries to import requests which doesn't yet exist in the environment. This is ssh_import_id.__init__.py
:
import argparse import json import logging import os import platform import requests # <= == here import stat import subprocess import sys import tempfile
A fix has been added which works around needing to import the package to get the version...
import os
from setuptools
import setup
import sys
def read_version():
# shove 'version'
into the path so we can
import it without going through
# ssh_import_id which has deps that wont be available at setup.py time.
# specifically, from 'ssh_import_id import version'
# will fail due to requests not available.
verdir = os.path.abspath(
os.path.join(os.path.dirname(__file__), "ssh_import_id"))
sys.path.insert(0, verdir)
import version
return version.VERSION
The library's setup.py imports the library to get the version for inclusion in the setup() function call...,A fix has been added which works around needing to import the package to get the version...,... and the library tries to import requests which doesn't yet exist in the environment. This is ssh_import_id.__init__.py:,... but the fix isn't in the current pypi version 5.6.
I'm using Heroku as a development server. When I try to push my Django application to Heroku it first tries to install my packages from the requirements.txt
file.
requests == 2.18 .3
ssh -
import -id == 5.5
The problem is I have a dependency on one of my packages with others. In the above packages, ssh-import-id
needs requests
package already installed. So when I push the app, pip fails to install and stops the deployment.
Collecting requests==2.18.3 (from -r re.txt (line 1))
Using cached https://files.pythonhosted.org/packages/ba/92/c35ed010e8f96781f08dfa6d9a6a19445a175a9304aceedece77cd48b68f/requests-2.18.3-py2.py3-none-any.whl
Collecting ssh-import-id==5.5 (from -r re.txt (line 2))
Using cached https://files.pythonhosted.org/packages/66/cc/0a8662a2d2a781db546944f3820b9a3a1a664a47c000577b7fb4db2dfbf8/ssh-import-id-5.5.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-go0a5mxf/ssh-import-id/setup.py", line 20, in <module>
from ssh_import_id import __version__
File "/tmp/pip-install-go0a5mxf/ssh-import-id/ssh_import_id/__init__.py", line 25, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-go0a5mxf/ssh-import-id/
The library's setup.py
imports the library to get the version for inclusion in the setup()
function call...
import os
from setuptools
import setup
from ssh_import_id
import __version__
... and the library tries to import requests which doesn't yet exist in the environment. This is ssh_import_id.__init__.py
:
import argparse import json import logging import os import platform import requests # <= == here import stat import subprocess import sys import tempfile
A fix has been added which works around needing to import the package to get the version...
import os
from setuptools
import setup
import sys
def read_version():
# shove 'version'
into the path so we can
import it without going through
# ssh_import_id which has deps that wont be available at setup.py time.
# specifically, from 'ssh_import_id import version'
# will fail due to requests not available.
verdir = os.path.abspath(
os.path.join(os.path.dirname(__file__), "ssh_import_id"))
sys.path.insert(0, verdir)
import version
return version.VERSION
Last updated: Apr 20, 2022
Copied!#ποΈ in a virtual environment or using Python 2 pip install requests #ποΈ for python 3(could also be pip3 .10 depending on your version) pip3 install requests #ποΈ if you get permissions error sudo pip3 install requests #ποΈ if you don 't have pip in your PATH environment variable python - m pip install requests #ποΈ for python 3(could also be pip3 .10 depending on your version) python3 - m pip install requests #ποΈ alternative for Ubuntu / Debian sudo apt - get install python3 - requests #ποΈ alternative for CentOS sudo yum install python - requests #ποΈ for Anaconda conda install - c anaconda requests
Copied!
import requests
def make_request():
res = requests.get('https://reqres.in/api/users')
print(res.json())
make_request()
Copied!python--version
Copied!pip3 .10 install requests #ποΈ if you get permissions error use pip3(NOT pip3.X) sudo pip3 install requests
Copied!#ποΈ make sure to use your version of Python, e.g.3.10
python3 - m pip install requests
Copied!#ποΈ check if you have requests installed pip3 show requests #ποΈ if you don 't have pip setup in PATH python3 - m pip show requests
This is unrelated to the issue, but we strongly recommend you upgrade to the separate google-cloud-* packages. The google-cloud package hasn't been updated in quite some time now.,Could you check which version of requests and urllib3 is being installed? requests.packages has been around for a few years. See psf/requests#4071, Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. ,@arithmetic1728 Is there an additional package that needs to be installed for the SSL support?
from google.auth.transport.requests import AuthorizedSession
File "/home/travis/.local/lib/python3.4/site-packages/google/auth/transport/requests.py", line 38, in <module>
from requests.packages.urllib3.util.ssl_ import (
ImportError: No module named 'requests.packages'
pip3 install--user google - cloud
pip3 install--user--upgrade pip
pip3 install--user requests
pip3 install--user google - auth
(tmp) sijunliu @penguin: ~/wks/tmp$ python - m pip freeze DEPRECATION: Python 3.4 support has been deprecated.pip 19.1 will be the last one supporting it.Please upgrade your Python as Python 3.4 won 't be maintained after March 2019 (cf PEP 429). cachetools == 3.1 .1 certifi == 2019.11 .28 chardet == 3.0 .4 google - auth == 1.12 .0 idna == 2.8 pyasn1 == 0.4 .8 pyasn1 - modules == 0.2 .8 requests == 2.21 .0 rsa == 4.0 six == 1.14 .0 urllib3 == 1.24 .3 (tmp) sijunliu @penguin: ~/wks/tmp$ python Python 3.4 .9( default, Mar 26 2020, 14: 10: 47)[GCC 6.3 .0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from google.auth.transport.requests import AuthorizedSession >>>
python3 is already the newest version(3.4 .0 - 0 ubuntu2). The following additional packages will be installed: python - chardet - whl python - colorama - whl python - distlib - whl python - html5lib - whl python - pip - whl python - requests - whl python - setuptools - whl python - six - whl python - urllib3 - whl python3 - chardet python3 - colorama python3 - distlib python3 - html5lib python3 - pkg - resources python3 - requests python3 - setuptools python3 - six python3 - urllib3 Suggested packages: python3 - genshi python3 - lxml Recommended packages: python3 - wheel The following NEW packages will be installed: python - chardet - whl python - colorama - whl python - distlib - whl python - html5lib - whl python - pip - whl python - requests - whl python - setuptools - whl python - six - whl python - urllib3 - whl python3 - chardet python3 - colorama python3 - distlib python3 - html5lib python3 - pip python3 - pkg - resources python3 - requests python3 - setuptools python3 - six python3 - urllib3
Installing collected packages: pip
Successfully installed pip
Cleaning up...
Requirement already satisfied(use--upgrade to upgrade): requests in /usr/lib / python3 / dist - packages
Cleaning up...
Downloading / unpacking google - auth
Downloading / unpacking six >= 1.9 .0(from google - auth)
Downloading six - 1.14 .0 - py2.py3 - none - any.whl
Downloading / unpacking rsa >= 3.1 .4, < 4.1(from google - auth)
Downloading rsa - 4.0 - py2.py3 - none - any.whl
Downloading / unpacking pyasn1 - modules >= 0.2 .1(from google - auth)
Downloading / unpacking cachetools >= 2.0 .0, < 5.0(from google - auth)
Downloading cachetools - 4.0 .0 - py3 - none - any.whl
Downloading / unpacking setuptools >= 40.3 .0(from google - auth)
Downloading / unpacking pyasn1 >= 0.1 .3(from rsa >= 3.1 .4, < 4.1 - > google - auth)
Installing collected packages: google - auth, six, rsa, pyasn1 - modules, cachetools, setuptools, pyasn1
Successfully installed google - auth six rsa pyasn1 - modules cachetools setuptools pyasn1
Cleaning up...
[0 K$ python - m pip freeze /
usr / local / lib / python2 .7 / dist - packages / pip / _vendor / requests / packages / urllib3 / util / ssl_.py: 318: SNIMissingWarning: An HTTPS request has been made, but the SNI(Subject Name Indication) extension to TLS is not available on this platform.This may cause the server to present an incorrect TLS certificate, which can cause validation failures.You can upgrade to a newer version of Python to solve this.For more information, see https: //urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
SNIMissingWarning /
usr / local / lib / python2 .7 / dist - packages / pip / _vendor / requests / packages / urllib3 / util / ssl_.py: 122: InsecurePlatformWarning: A true SSLContext object is not available.This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail.You can upgrade to a newer version of Python to solve this.For more information, see https: //urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning /
usr / local / lib / python2 .7 / dist - packages / pip / _vendor / requests / packages / urllib3 / util / ssl_.py: 122: InsecurePlatformWarning: A true SSLContext object is not available.This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail.You can upgrade to a newer version of Python to solve this.For more information, see https: //urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
You are using pip version 9.0 .1, however version 20.0 .2 is available.
You should consider upgrading via the 'pip install --upgrade pip'
command.
apt - xapian - index == 0.45
boto == 2.20 .1
bzr == 2.7 .0.dev1
chardet == 2.0 .1
Cheetah == 2.4 .4
cloud - init == 0.7 .5
configobj == 4.7 .2
crcmod == 1.7
google - compute - engine == 2.2 .4
jsonpatch == 1.3
jsonpointer == 1.0
Landscape - Client == 14.12
mercurial == 4.2 .2
oauth == 1.0 .1
PAM == 0.4 .2
prettytable == 0.7 .2
pycurl == 7.19 .3
pyOpenSSL == 0.13
pyserial == 2.6
python - apt === 0.9 .3 .5 ubuntu2
python - debian === 0.1 .21 - nmu2ubuntu2
PyYAML == 3.10
requests == 2.2 .1
six == 1.5 .2
ssh -
import -id == 3.21
Twisted - Core == 13.2 .0
Twisted - Names == 13.2 .0
Twisted - Web == 13.2 .0
urllib3 == 1.7 .1
virtualenv == 15.1 .0
zope.interface == 4.0 .5
If you are installing your Python packages manually, not using Anaconda / MiniConda or other prepackaged distribution, itβs easily to use the Python package management utility (PIP) to solve this issue. Iβll go through the steps in a Windows computer, those will be pretty quite similar in macOS or Linux distributions.,Solution: ensure that you have indeed closed your Python editor before importing the package. If still you get and error, reboot your Windows PC and try again.,Issue: you are still getting the import error even after executing the installation using pip or the Anaconda Environment Manager.,In this post i will show you how to easily troubleshoot requests import errors in your Python development environment of choice, being it Jupyter, PyCharm, Spyder etcβ and distribution.
- First, go ahead and close your Python editor environment.
- Then open your command line ( Windows: Start >> run >> cmd) or Terminal.
- Now type the following command:
pip install requests
- Next, go ahead and close your command or Terminal window.
- Now go ahead and reopen your Python editor and import requests.
import requests as re
Issue: When trying to import the requests module from the Python package repository, you encounter errors:
ERROR: Could not find a version that satisfies the requirement requests(from versions: none)