Import error in Flask (urllib in local path) - python

Am facing the below error while trying to import Flask. Similar questions posted had issues with Werkzeug versions
from urllib.request import parse_http_list as _parse_list_header
ImportError: No module named request
File "init__.py", line 25, in <module>
from flask import Flask
File "user/anaconda/lib/python2.7/site-packages/flask/__init__.py", line 17,
in <module>
from werkzeug.exceptions import abort
File "user/anaconda/lib/python2.7/site-packages/werkzeug/__init__.py", line
154, in <module>
__import__('werkzeug.exceptions')
File "user/anaconda/lib/python2.7/site-packages/werkzeug/exceptions.py", line
71, in <module>
from werkzeug.wrappers import Response
File "user/anaconda/lib/python2.7/site-packages/werkzeug/wrappers.py", line
26, in <module>
from werkzeug.http import HTTP_STATUS_CODES, \
File "user/anaconda/lib/python2.7/site-packages/werkzeug/http.py", line 28, in
<module>
from urllib.request import parse_http_list as _parse_list_header
ImportError: No module named request'
Werkzeug version(I tried with 10.1,10.4 ) still the error remains.
Someone pointed out that there might be a local copy of urllib2.. I
figured out that there was both urllib and urllib2 indeed in my
local path..
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
Now I am not sure how to proceed, Should I uninstall urllib/urllib2 ?
EDIT: The solution listed in Tried to use relative imports, and broke my import paths? doesn't work for me. In this case, I tried importing urllib2 into my Flask project and printing out the file path, but that throws the below exceptions
File "/user/__init__.py", line 25, in <module>
import urllib2
File "/user/anaconda/lib/python2.7/urllib2.py", line 94, in <module>
import httplib
File "/user/anaconda/lib/python2.7/httplib.py", line 80, in <module>
import mimetools
File "/user/anaconda/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/user/anaconda/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
File "/user/anaconda/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/user/anaconda/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
Referenced from: /user/anaconda/lib/python2.7/lib-dynload/_io.so
Expected in: dynamic lookup

I had a similar issue, and I followed the recommendation in the solution by adding from urllib2 import parse_http_list as _parse_list_header before from flask import Flask, then I got this error message:
"/Users/anaconda/lib/python2.7/io.py", line 51, in import _io
ImportError: dlopen(/Users/anaconda/lib/python2.7/lib-dynload/_io.so, 2):
Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /Users/anaconda/lib/python2.7/lib-dynload/_io.so
Expected in: dynamic lookup
which I then resolved by following the solution:
sudo find / -name _io.so
I replaced /Users/anaconda/lib/python2.7/lib-dynload/_io.so with /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
It works for me!

In my case, one of my python-modules named uu. Such as a file in python3-email module.
... line 4, in <module>
import flask
File "/usr/lib/python3/dist-packages/werkzeug/http.py", line 28, in <module>
from urllib.request import parse_http_list as _parse_list_header
File "/usr/lib/python3.4/urllib/request.py", line 88, in <module>
import http.client
File "/usr/lib/python3.4/http/client.py", line 69, in <module>
import email.parser
File "/usr/lib/python3.4/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.4/email/feedparser.py", line 27, in <module>
from email import message
File "/usr/lib/python3.4/email/message.py", line 10, in <module>
import uu
Then, i have the same error:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/werkzeug/http.py", line 26, in <module>
from urllib2 import parse_http_list as _parse_list_header
ImportError: No module named 'urllib2'
I hope, this example will help you.

Related

I can't use urllib3 or urllib in python 3.8 [duplicate]

This question already has answers here:
How can I import from the standard library, when my project has a module with the same name? (How can I control where Python looks for modules?)
(6 answers)
Closed 2 years ago.
I just installed urllib3 using pip command and was successful, and when i use import urllib3 or import urllib its showing a huge error. Why this happening?. Please help.
This is my error: when use import urllib or import urllib3 and running in sublime text.
Traceback (most recent call last):
File "C:\Users\Toshiba\Desktop\dd.py", line 1, in <module>
import urllib3
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\__init__.py", line 7, in <module>
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 11, in <module>
from .exceptions import (
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\exceptions.py", line 2, in <module>
from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\packages\six.py", line 199, in load_module
mod = mod._resolve()
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\packages\six.py", line 113, in _resolve
return _import_module(self.mod)
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\packages\six.py", line 82, in _import_module
__import__(name)
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 71, in <module>
import email.parser
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\email\feedparser.py", line 27, in <module>
from email._policybase import compat32
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\email\_policybase.py", line 9, in <module>
from email.utils import _has_surrogates
File "C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\email\utils.py", line 31, in <module>
import urllib.parse
File "C:\Users\Toshiba\Desktop\urllib.py", line 2, in <module>
from urllib3 import PoolManager
ImportError: cannot import name 'PoolManager' from partially initialized module 'urllib3' (most likely due to a circular import) (C:\Users\Toshiba\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\__init__.py)
File "C:\Users\Toshiba\Desktop\urllib.py", line 2, in
One of your files is called urllib. Rename it.
That's one of the issues but I'm not sure it's the root cause of your problem. It seems like your installation is broken. If renaming this file didn't help, I'd suggest to start with a new virtualenv. If you're not using one, start with that.

No Calendar package is imported

When trying to run the following script:
import matplotlib as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
I exeperience the following error:
C:\Users\raja\PycharmProjects\Project_test\venv\Scripts\python.exe C:/Users/raja/.PyCharmCE2018.2/config/scratches/testing.py
Traceback (most recent call last):
File "C:/Users/raja/.PyCharmCE2018.2/config/scratches/testing.py", line 1, in <module>
import matplotlib as plt
File "C:\Users\raja\PycharmProjects\Project_test\venv\lib\site-packages\matplotlib\__init__.py", line 136, in <module>
import urllib.request
File "C:\Users\raja\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 88, in <module>
import http.client
File "C:\Users\raja\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 71, in <module>
import email.parser
File "C:\Users\raja\AppData\Local\Programs\Python\Python37\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "C:\Users\raja\AppData\Local\Programs\Python\Python37\lib\email\feedparser.py", line 27, in <module>
from email._policybase import compat32
File "C:\Users\raja\AppData\Local\Programs\Python\Python37\lib\email\_policybase.py", line 9, in <module>
from email.utils import _has_surrogates
File "C:\Users\raja\AppData\Local\Programs\Python\Python37\lib\email\utils.py", line 33, in <module>
from email._parseaddr import quote
File "C:\Users\raja\AppData\Local\Programs\Python\Python37\lib\email\_parseaddr.py", line 16, in <module>
import time, calendar
File "C:\Users\raja\.PyCharmCE2018.2\config\scratches\calendar.py", line 7, in <module>
import tkcalendar
ModuleNotFoundError: No module named 'tkcalendar'
Why? Does anybody know how to solve this issue?
I have fixed it. there was a different python program I named it as Calendar.py :(. I have deleted that file from "config/scratches/" and it has fixed the issue.
Also I have deleted the two versions of Tkcalendar installed

Selenium Python Ubuntu- Import http.client AttributeError

It's been days i'm fighting with this error.
My background is :
- Clean install of Lubuntu ( based on ubuntu 15 ) w/ just setuptools and selenium 2.50 installed
- A selenium python3 script.
I tried running this script w/ an other machine ( lubuntu based on ubuntu 14 ) and it runs, but with the new machine, all the scripts doesn't work.
I looked up on the big internet but i couldn't find an answer.
I have the following error :
Traceback (most recent call last):
File "tesst.py", line 1, in <module>
from selenium import webdriver
File "/usr/local/lib/python3.4/dist-packages/selenium-2.50.0-py3.4.egg/selenium/__init__.py", line 18, in <module>
from selenium import selenium
File "/usr/local/lib/python3.4/dist-packages/selenium-2.50.0-py3.4.egg/selenium/selenium.py", line 23, in <module>
import http.client as http_client
File "/usr/lib/python3.4/http/client.py", line 69, in <module>
import email.parser
File "/usr/lib/python3.4/email/parser.py", line 12, in <module>
from email.feedpaarser import FeedParser, BytesFeedParser
File "/usr/lib/python3.4/email/feedparser.py", line 27, in <module>
from email import message
File "/usr/lib/python3.4/email/message.py", line 16, in <module>
from email import utils
File "/usr/lib/python3.4/email/utils.py", line 33, in <module>
from email._parseaddr import quote
File "/usr/lib/python3.4/email/_parseaddr.py", line 16, in <module>
import time, calendar
File "/home/XXXX/Scripts/XXXX/calendar.py", line 1, in <module>
from selenium import webdriver
File "/usr/local/lib/python3.4/dist-packages/selenium-2.50.0-py3.4.egg/selenium/webdriver/__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox
File "/usr/local/lib/python3.4/dist-packages/selenium-2.50.0-py3.4.egg/selenium/webdriver/firefox/webdriver.py", line 20, in <module>
import http.client as http_client
AttributeError: 'module' object has no attribute 'client'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 21, in <module>
from urllib.request import urlopen
File "/usr/lib/python3.4/urllib/request.py", line 88, in <module>
import http.client
File "/usr/lib/python3.4/http/client.py", line 69, in <module>
import email.parser
File "/usr/lib/python3.4/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.4/email/feedparser.py", line 27, in <module>
from email import message
File "/usr/lib/python3.4/email/message.py", line 16, in <module>
from email import utils
File "/usr/lib/python3.4/email/utils.py", line 33, in <module>
from email._parseaddr import quote
File "/usr/lib/python3.4/email/_parseaddr.py", line 16, in <module>
import time, calendar
File "/home/XXXX/Scripts/XXXX/calendar.py", line 1, in <module>
from selenium import webdriver
File "/usr/local/lib/python3.4/dist-packages/selenium-2.50.0-py3.4.egg/selenium/__init__.py", line 18, in <module>
from selenium import selenium
File "/usr/local/lib/python3.4/dist-packages/selenium-2.50.0-py3.4.egg/selenium/selenium.py", line 23, in <module>
import http.client as http_client
AttributeError: 'module' object has no attribute 'client'
Original exception was:
Traceback (most recent call last):
File "tesst.py", line 1, in <module>
from selenium import webdriver
File "/usr/local/lib/python3.4/dist-packages/selenium-2.50.0-py3.4.egg/selenium/__init__.py", line 18, in <module>
from selenium import selenium
File "/usr/local/lib/python3.4/dist-packages/selenium-2.50.0-py3.4.egg/selenium/selenium.py", line 23, in <module>
import http.client as http_client
File "/usr/lib/python3.4/http/client.py", line 69, in <module>
import email.parser
File "/usr/lib/python3.4/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.4/email/feedparser.py", line 27, in <module>
from email import message
File "/usr/lib/python3.4/email/message.py", line 16, in <module>
from email import utils
File "/usr/lib/python3.4/email/utils.py", line 33, in <module>
from email._parseaddr import quote
File "/usr/lib/python3.4/email/_parseaddr.py", line 16, in <module>
import time, calendar
File "/home/XXXX/Scripts/XXXX/calendar.py", line 1, in <module>
from selenium import webdriver
File "/usr/local/lib/python3.4/dist-packages/selenium-2.50.0-py3.4.egg/selenium/webdriver/__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox
File "/usr/local/lib/python3.4/dist-packages/selenium-2.50.0-py3.4.egg/selenium/webdriver/firefox/webdriver.py", line 20, in <module>
import http.client as http_client
I looked a lot before coming here but i'm kinda lost right now. Can someone please help, i'll be very greatful.
Thanks !!
Edit :
Hey, i already try all of that, but it's not fixing the issue. I don't have duplicate selenium, i just install
sudo python3 setup.py install in selenium dir. Also i don't have a script called http.py, so when i do import http http.__file__ it gives me /usr/lib/python3.4/http/__init__.py
Ok, let's face it, i knew it, the answer was just in front of my eyes. S**t !!
This
File "/home/XXXX/Scripts/XXXX/calendar.py", line 1, in
I had a script name calendar.py as a module... So changing the name made the job.
Sorry guys, and thank you

What module is missing when I try to import skimage? Python 3.5

When I run the line from skimage import io I get the following:
Traceback (most recent call last):
File "C:\Users\Dilshad\Desktop\project_7-8-2015\8_bands\Program_camera.py", line 16, in <module>
from Functions_8bands import *
File "C:\Users\Dilshad\Desktop\project_7-8-2015\8_bands\Functions_8bands.py", line 5, in <module>
from skimage import io
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\skimage\io\__init__.py", line 11, in <module>
from ._io import *
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\skimage\io\_io.py", line 8, in <module>
from ..color import rgb2grey
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\skimage\color\__init__.py", line 1, in <module>
from .colorconv import (convert_colorspace,
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\skimage\color\colorconv.py", line 58, in <module>
from scipy import linalg
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\linalg\__init__.py", line 172, in <module>
from .misc import *
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\linalg\misc.py", line 5, in <module>
from .blas import get_blas_funcs
File "C:\Users\Dilshad\AppData\Local\Programs\Python\Python35\lib\site-packages\scipy\linalg\blas.py", line 155, in <module>
from scipy.linalg import _fblas
ImportError: DLL load failed: The specified module could not be found.
I've searched through the site-package file and I see that io exists so I'm not really sure whats's missing.
Not sure why it worked but installing numpy +mkl instead of numpy vanilla from the unofficial binary site on UCI got around this for me.

Error when using requests In Python2.7

import requests
r = requests.get('http://bbs.byr.cn/')
print r
The error:
Traceback (most recent call last): File
"E:\MyPythonRoad\src\requeststest.py", line 1, in
import requests File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests__init__.py",
line 58, in
from . import utils File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests\utils.py",
line 25, in
from .compat import parse_http_list as _parse_list_header File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests\compat.py",
line 7, in
from .packages import chardet File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests\packages__init__.py",
line 3, in
from . import urllib3 File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests\packages\urllib3__init__.py",
line 16, in
from .connectionpool import ( File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests\packages\urllib3\connectionpool.py",
line 36, in
from .connection import ( File "C:\Python27\lib\site-packages\requests-2.3.0-py2.7.egg\requests\packages\urllib3\connection.py",
line 43, in
from .util import ( ImportError: No module named util
requests
Since you are using Windows, you may want to try to reinstall requests through this binary.
urllib3
According to this, you may want to try manual download the util folder from urilib3 from the download at the bottom of pypi, and add it to the urllib3 install location.

Categories

Resources