I am trying to use the Python Library requests using Liclipse. I have added the library but it is giving me the below error message
Traceback (most recent call last):
File "C:\programming\automate_boring_stuff\test.py", line 1, in <module>
import requests
File "C:\programming\libraries\kennethreitz-requests-> > 00fa5f1\requests\__init__.py", line 3, in <module>
from . import ssl_match_hostname
ImportError: cannot import name ssl_match_hostname
Unusually I was previously using it on another computer and it worked finebut on this one by just running import requests it gives me the above error message.
I have tried researching this but most of the answers I have found have been related to different libraries and I could not find how the fixes related to the requests library.
You have mucked up your installation; you appear to have moved the requests/packages/urllib3/packages/__init__.py file into the top-level requests folder.
Remove the package and re-install.
Related
When i try to run ovirt downloads_disk_snapshot from this link i am getting error as
Traceback (most recent call last):
File "download_disk_snapshots.py", line 22, in <module>
import ovirtsdk4 as sdk
ImportError: No module named ovirtsdk4
Link is https://github.com/oVirt/ovirt-engine-sdk/blob/master/sdk/examples/download_disk_snapshots.py
This guide gives some very useful information on installing python packages.
In your case, you will have to install the oVirt Engine SDK itself before being able to run the example.
Installation instructions are given within the same Github project that you are mentioning:
https://github.com/oVirt/ovirt-engine-sdk/blob/master/sdk/README.adoc#installation
I've seen this question asked before but none of the answers seem to work for me.
I am using python version 2.7.13
In my code I have ..
import base64
import httplib2
Now when I run it on my own pc it works fine, but when I run it on my works p.c. behind a firewall I get ..
Traceback (most recent call last):
File "mail4.py", line 2, in
import httplib2
File "C:\Python27\lib\site-packages\httplib2__init__.py", line 39, in
import urllib
File "C:\mypy\urllib.py", line 1, in
import requests
File "C:\Python27\lib\site-packages\requests__init__.py", line 43, in
import urllib3
File "C:\Python27\lib\site-packages\urllib3__init__.py", line 8, in
from .connectionpool import (
File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 35, in
from .request import RequestMethods>
File "C:\Python27\lib\site-packages\urllib3\request.py", line 10, in >
from .packages.six.moves.urllib.parse import urlencode
ImportError: cannot import name urlencode
I've tried setting proxies.
I've tried uninstalling and re-installing six
Also
from urllib.parse import urlencode
All to no avail ?
You are (in this case) apparently running Python 2.7.x, however parse module is in urllib package in Python 3.x. In Python 2.x its name was (just) urlparse. Based on that, I'd guess different configuration (mismatch in versions used between Code and/or 3rd party packages and/or python interpreter is behind the problem you're seeing).
EDIT: sorry, I should have also noticed you are looking for urlencode on the last bit. In python 2.7 that is a function in urllib module: from urllib import urlencode.
I fixed this issue with installing Werkzeug to <1.0, which removed the contrib module
pip install Werkzeug==0.16.1
$ python3 setup-py install
....
Installed /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/twitter-1.17.1-py3.5.egg
Processing dependencies for twitter==1.17.1
Finished processing dependencies for twitter==1.17.1
$ python3 twitter.py
Traceback (most recent call last):
File "twitter.py", line 1, in <module>
from twitter import Twitter
File "/Users/eddiee/2_python/twitter.py", line 1, in <module>
from twitter import Twitter
ImportError: cannot import name 'Twitter'
What might cause the problem:
Due to the restrictions of the preinstalled python on Mac, I installed another new python and changed the path. But I don't know how to install the module to the new python.
Eddie:
Try to change the import line to:
import twitter
or:
from twitter import Twitter
Hope it helps.
The problem here is I names my file as "twitter.py". When I imported the twitter module, python automatically imported the file itself, because the current file has a higher priority over the module. Simply changing the file name can solve the problem.
I'm using Tweepy to send some messages to Twitter. I'm getting a long traceback from the API. The traceback settles at:
ImportError: cannot import name Random
I used Pip to install the latest version of Tweepy:
Name: tweepy
Version: 2.3.0
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Requires:
When I call
import tweepy
I get this traceback:
Traceback (most recent call last):
File "/Users/dromard/Projects/Drop Playlist/drop.py", line 4, in <module>
import tweepy
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/__init__.py", line 14, in <module>
from tweepy.api import API
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/api.py", line 8, in <module>
from tweepy.binder import bind_api
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tweepy/binder.py", line 5, in <module>
import httplib
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 79, in <module>
import mimetools
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
import tempfile
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
ImportError: cannot import name Random
Process finished with exit code 1
I'm working in PyCharm and confirmed the site package and Python paths are correct in settings. I manually checked in console that the paths are correct, and there are no duplicate locations.
I haven't made any changes to Tweepy. I let Pip install it where it is, as it is. Permissions look correct:
-rw-r--r-- 1 root wheel
If I check Python in console:
- I get the same traceback
- When I run the individual imports, they all execute without error
It all fails out at the random call. I think random is part of Python's core packages, and not part of Tweepy.
I handed this script off to a co-worker, who then used Pip to install tweepy and hit the same traceback. Makes me think Pip might be contributing.
I'm relatively new to Python (programming in general). I looked through other 'import error' articles, but didn't find this specific issue. Any help is appreciated.
I figured this out.
I had created a python file called 'random.py' during the course of experimenting with a random number generating script. My 'import random' call was grabbing this file, which lacked the library Random. It essentially created a conflict with the proper 'random.'
Make sure that you delete the random.py file or overwrite it with another name, then recheck "from random import random".
I could not comment due to low experience.
I also had a xyz.py in a directory and calling a module of same name (import xyz) causes this error.
Make sure you do not save any file xyz.py that also have a python module at the same name.
This is what I found from my newbie experiment.
This also happens with python 3.8.
I cannot import GeoIP in django. I searched and tested this error two days, but still could not know problem.
Surely, I installed GeoDjango. I'm on MacOS 10.8
following is log by tested by django shell
from django.contrib.gis import geoip
module 'django.contrib.gis.geoip' from '/Library/Python/2.7/site-packages/django/contrib/gis/geoip/__init__.pyc'
it works. even I could find geoip class at Library/Python/2.7/site-packages/django/contrib/gis/geoip/base.py
from django.contrib.gis.geoip import geoip
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name geoip
I also add django.contrib.gis to setting.py. Even I could find geoip class at eclipse shortcut.
anyway, I tested one more thing in django shell.
from django.contrib.gis.geoip.base import GeoIP
Traceback (most recent call last):
File "", line 1, in
File "/Library/Python/2.7/site-packages/django/contrib/gis/geoip/base.py", line 6, in
from django.contrib.gis.geoip.libgeoip import GEOIP_SETTINGS
File "/Library/Python/2.7/site-packages/django/contrib/gis/geoip/libgeoip.py", line 22, in
if lib_path is None: raise GeoIPException('Could not find the GeoIP library (tried "%s"). '
NameError: name 'GeoIPException' is not defined
What I missing?
Is there any way to test my error?
It appears you need to install a C library in order to use GeoIP.
Here is a snippet from the file that is throwing that error.
# The shared library for the GeoIP C API. May be downloaded
# from http://www.maxmind.com/download/geoip/api/c/
if lib_path:
lib_name = None
else:
# TODO: Is this really the library name for Windows?
lib_name = 'GeoIP'
Once you have it installed somewhere you need to reference it in your settings.py
GEOIP_LIBRARY_PATH = '/whatever'
The library was trying to tell you this, but it seems that there is a bug that prevents it from raising the correct error. https://github.com/django/django/pull/103
Previously i was facing this issue : from django.contrib.gis.geoip import GeoIP ImportError: cannot import name GeoIP
which is solved when i install this package.
yum install GeoIP-devel -y
The error is caused by moving the virtual environment folder.
The solution is to create the environment again and reinstall the pygeoip library.