Python urllib.request - no module named request - python-requests

I've read through many similar posts but none solve my problem. When trying to import requests I get a response saying no module named request.
Fresh install of Ubuntu 15.04
I've installed pip3
I've installed requests
Here is the latest output :
binx#Binx:~/Python$ sudo pip3 install requests --upgrade
Downloading/unpacking requests from https://pypi.python.org/packages/2.7/r/requests/requests-2.7.0-py2.py3-none-any.whl#md5=564fb256f865a79f977e57b79d31659a
Downloading requests-2.7.0-py2.py3-none-any.whl (470kB): 470kB downloaded
Installing collected packages: requests
Found existing installation: requests 2.2.1
Not uninstalling requests at /usr/lib/python3/dist-packages, owned by OS
Successfully installed requests
Cleaning up...
binx#Binx:~/Python$ python connect.py
Traceback (most recent call last):
File "connect.py", line 7, in
import urllib.request
ImportError: No module named request
binx#Binx:~/Python$

It would be best if you could show the code of your connect.py file.
From what I see now I'd guess that you're running python 2.x because only in python3 urllib was split to urllib.request. Find out what version is being ran after typing 'python' into terminal and try to use 'python3' instead.
Also I see you're new here so don't forget to accept answer as correct if someone posts correct answer.

Related

Lambda function failing with /lib64/libc.so.6: version `GLIBC_2.18' not found

I am trying to create a layer of simple-salesforce (Python Library) in AWS lambda, and trying to use it (import it) from my python code. I am having windows machine.
Though I read that there might be issues due to compilation windows so I install ubuntu1804 from windows store and then went ahead with creating zip for lambda layers. (zip is created for python folder with structure "python/lib/python3.6/site-packages/......")
I am using Python 3.6. I went through few articles for this issue but could find any resolution. this Video helped me creating a layer for Pandas & requests in AWS successfully with minor tweaks in pip commands I used
sudo python3 -m pip install simple-salesforce -t build/python/lib/python3.6/site-packages
Exactly same process i used for Simple salesforce and I am getting below error is as below:
Unable to import module 'lambda_function': /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /opt/python/lib/python3.6/site-packages/cryptography/hazmat/bindings/_rust.abi3.so)
Edit: --
Another approach I tried using .whl though this was not giving above error but giving error as "request module not found" and when I add request module layer it gives error authlib not found. (request layers work fine if I comment salesforce related things. Even tried uploading as simple layer same authlib issue I got)
Edit :
Lambda code I am using is as below
the code I am using is basic code which doesnt have any logic with empty imports
import json
import pandas as pd
import requests as req
from simple_salesforce.format import format_soql
def lambda_handler(event, context):
#TODO
I also received the same error while installing pysftp on lambda which uses cryptography library(python)
the error was similiar to (required by /opt/python/lib/python3.6/site-packages/cryptography/hazmat/bindings/_rust.abi3.so)
The solution that worked for me is
1] pip uninstall cryptography
2] pip install cryptography==3.4.8
The following github link explains it in detail
https://github.com/pyca/cryptography/issues/6390
AWS lambda functions are like virtual environments, they do not come with the .so files which are kernel level packages. When installing the python packages you have to make sure the system dependent files are installed with it. This can be achieved by passing the argument --platform to pip install.
From AWS post How do I add Python packages with compiled binaries to my deployment package and make the package compatible with Lambda?:
To create a Lambda deployment package or layer that's compatible with Lambda Python runtimes when using pip outside of Linux operating system, run the pip install command with manylinux2014 as the value for the --platform parameter.
pip install \
--platform manylinux2014_x86_64 \
--target=my-lambda-function \
--implementation cp \
--python 3.9 \
--only-binary=:all: --upgrade \
simple-salesforce
I changed my code to not use simple_salesforce library and work out all the logic with Requests ( using Salesforce REST APIs).
This is not really ideal but I could get it working as I had some deliveries to meet.

Anaconda Navigator Jupyter and Spyder won't start after successful installation

I have installed Anaconda 3 on Windows 10 64-bit. The installation completed successfully. I could start idle.exe and it works. I can start the Anaconda Powershell and Anaconda Prompt, but I cannot start the Navigator nor Spyer or Jupyter. Launching them from the start menu will bring up the Windows shell windows for a moment, before they disappear and nothing happens.
I have tried starting the navigator from the Anaconda Prompt and this is what the error message looks like:
(base) PS C:\Users\Frank> anaconda-navigator.exe
Traceback (most recent call last):
File "C:\Users\Frank\Anaconda3\Scripts\anaconda-navigator-script.py", line 10, in <module>
sys.exit(main())
File "C:\Users\Frank\Anaconda3\lib\site-packages\anaconda_navigator\app\main.py", line 103, in main
from anaconda_navigator.app.start import start_app
File "C:\Users\Frank\Anaconda3\lib\site-packages\anaconda_navigator\app\start.py", line 34, in <module>
from anaconda_navigator.widgets.main_window import MainWindow
File "C:\Users\Frank\Anaconda3\lib\site-packages\anaconda_navigator\widgets\main_window.py", line 37, in <module>
from anaconda_navigator.utils.analytics import GATracker
File "C:\Users\Frank\Anaconda3\lib\site-packages\anaconda_navigator\utils\analytics.py", line 44, in <module>
from anaconda_navigator.external.UniversalAnalytics import Tracker
File "C:\Users\Frank\Anaconda3\lib\site-packages\anaconda_navigator\external\UniversalAnalytics\Tracker.py", line 28, in <module>
from six.moves.urllib.request import (HTTPSHandler, Request, build_opener,
ImportError: cannot import name 'HTTPSHandler' from 'six.moves.urllib.request' (unknown location)
I have searched the internet for root causes of the last line in the error message with no success. There are a few tips how to fix it, but nothing worked.
The exact version I have installed is Anaconda3-2019.10-Windows-x86_64.exe.
I have tried uninstalling and reinstalling Anaconda in all different "flavors":
for all users, without adding the path to the environment variables
for all users, with adding the path to the environment variables for
current user, without adding the path to the environment variables
for current user, with adding the path to the environment variables
Anaconda is installed into a directory without spaces in its name and no fancy characters: c:\users\frank\Anaconda3.
I have removed .anaconda and tried launching the navigator, spyer and jupyter again with no success.
Spyer comes up with a message that it had crashed during the last session. I followed the advice and deleted the .spyder-py3 folder, but no change.
How can I find more information about the reason for the problem on my system? Are there any log files that contain more information? I checked if HTTPSHandler is defined where Anaconda would search for it (please consider my limited expertise in Anaconda, when assuming where to look for resources...).
I installed the same Anaconda3 version on another computer and it works right from the start.
After reading another suggestion about updating conda using conda update conda and trying it on the Anaconda prompt I received the following error:
(base) PS C:\Users\Frank> conda update conda
Collecting package metadata (current_repodata.json): failed
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/win-64/current_repodata.json>
Elapsed: -
An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.
If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.
SSLError(MaxRetryError('HTTPSConnectionPool(host=\'repo.anaconda.com\', port=443): Max retries exceeded with url: /pkgs/main/win-64/current_repodata.json (Caused by SSLError("Can\'t connect to HTTPS URL because the SSL module is not available."))'))
I had the idea that SSL could be a problem and uninstalled OpenSSL v1.1.0g (Win64), then checked again. That doesn't help. Installing OpenSSL v1.1.0g (Win64) again doesn't make a difference either. On the other hand I would have assumed that Anaconda brings all components and modules it needs.
Any ideas how to continue troubleshooting?
I kept digging for answers and came across a discussion at GitHub:
CondaHTTPError: Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available)
I followed the advice, uninstalled my OpenSSL version and installed the latest one from the page https://slproweb.com/products/Win32OpenSSL.html. This is now "Win64 OpenSSL v1.1.1d" and right after the installation all the issues with Anaconda were gone. I can use conda to update, the Anaconda Navigator comes up, Jupyter Notebook works. All is fine.

Need to restart runtime before import an installed package in Colab

I am trying to install and use an existing python package in Google Colab. For this, I download the code from Github in Colab and install the package, but when trying to import the installed package, I get a ModuleNotFoundError: No module named 'gem' Error.
However, if I restart the runtime and run the importing cell again, then no error appears.
I am wondering why I need to restart the runtime after installing the package and before importing.
Any clever response will be much appreciated.
My code is:
[1] !wget --show-progress --continue -O /content/gem.zip https://github.com/palash1992/GEM/archive/master.zip
[2] !unzip gem.zip
# Installing Dependencies
[3] ! pip install keras==2.0.2
[4] %cd GEM-master
!sudo python3 setup.py install
%cd-
[5] from gem.utils import graph_util, plot_util
And the error that I get is:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-af270a37878a> in <module>()
1 import matplotlib.pyplot as plt
2
----> 3 from gem.utils import graph_util, plot_util
4 from gem.evaluation import visualize_embedding as viz
5 from gem.evaluation import evaluate_graph_reconstruction as gr
ModuleNotFoundError: No module named 'gem'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
However, if I restart the runtime using os.kill(os.getpid(), 9) after installing the package and before importing it, then the above error does not appear.
It seems that everything except simple !pip installs seem to not get included in colab's module registry except after a runtime restart. Likely, colab has a fairly naive way of keeping track of available modules. You also have to restart the runtime if you import a different version of a previously installed package.
Probably they just have a script that appends the metadata for piply installed packages to a list-like object during runtime. And imports just search from the top of the list (which is why the restart is required for diff versions of packages).
However, when a new runtime is started, the list-like registry is initialized and populated by searching the relevant directories.
To force a restart:
try:
from gem.utils import graph_util, plot_util
except (ImportError, KeyError, ModuleNotFoundError):
## code to install gem
print('Stopping RUNTIME. Colaboratory will restart automatically. Please run again.')
exit()
Based on multiple answers to Google Colab - How to 'restart runtime' using python code or command line interface?.

ImportError: No module named 'requests' but, requests has been installed

I have installed requests on my mac, but the error message says the library does not exist. I have included "import requests" on line one of my Python script. I am using Python 3 for the call because it supports Server Name Indication, which I guess I need for this? Any pointers/help is greatly appreciated!
As you can see, I have installed requests:
Daves-MacBook-Pro:documents Dave$ pip install requests
Requirement already satisfied (use --upgrade to upgrade): requests in /Library/Python/2.7/site-packages
Cleaning up...
However when I try to run my script I get this error message:
Daves-MacBook-Pro:documents Dave$ python3 perka_call.py
Traceback (most recent call last):
File "perka_call.py", line 1, in
import requests
ImportError: No module named 'requests'
Try installing requests module for Python3. You have installed it for Python2.7
This might do the job.
pip install --target='/usr/lib/python3.4/' requests
I am assuming you are using python3.4

Bokeh - Runserve.py fail

After hearing Peter Wang talk about the Bokeh plotting environment, I had to try it. The problem is I can't even get the examples to work because I can't get the plot server going. I verified the install of all listed dependencies, and installed continuumweb (a module that is curiously absent from the list of dependencies in the Bokeh README on github). However, I still encountered the error below. It looks like this should come out of continuumweb, but I find no trace of such a sub-module within the repo. Am I looking in the wrong place? (I have not found any other instances of this exception.)
If anyone could provide some guidance, I would be grateful...
choct155#choct155-U46E:~/analysis/anaconda/pkgs/Bokeh$ python runserver.py
Traceback (most recent call last):
File "runserver.py", line 3, in <module>
from bokeh.server import start
File "/home/choct155/analysis/anaconda/pkgs/Bokeh/bokeh/server/start.py", line 76, in <module>
import services
File "/home/choct155/analysis/anaconda/pkgs/Bokeh/bokeh/server/services.py", line 4, in <module>
from continuumweb.launch_process import ManagedProcess
ImportError: No module named launch_process
Exception KeyError: KeyError(139639237560272,) in <module 'threading' from '/home/choct155/analysis/anaconda/lib/python2.7/threading.pyc'> ignored
For those who are reading this later, we've had two versioned releases since the original question, and they are all easy to install directly from PyPI via "pip install bokeh". If you are using Anaconda, it's even easier to install via "conda install bokeh".
For some reason, the pip installer did not perform well here. I just started from scratch by cloning the continuumweb repository and installing from source ('python setup.py install' in the cloned directory)...
All is well.

Resources