$ 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.
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
Working on code that SSH's into terminal on an external device. This morning the code was able to do so. Then I updated Windows because I had put it off for a while. This was the only thing I did that I could think of may have had an effect.
I now run into a ModuleNotFoundError.
I tried updating pip, uninstalling and reinstalling ssh2-python. I changed python37 folder to read/write. Tried locating the module in python37/Lib/site-packages but not really sure what I'm looking for
SSH's into address' terminal
import socket
from ssh2.session import Session
Expected:
input for ip address
Result:
Traceback (most recent call last):
File "C:/Users/louis/Desktop/ssh2.py", line 4, in <module>
from ssh2.session import Session
File "C:\Users\louis\Desktop\ssh2.py", line 4, in <module>
from ssh2.session import Session
ModuleNotFoundError: No module named 'ssh2.session'; 'ssh2' is not a package
I had named a file in the same directory ssh2. Python loaded that instead of the module. Simply renamed the file to anything else and python was able to find the ssh2 module.
I have an issue with the gspread module, and I think with Python 3 too.
My code is something like that: import blabla, gspread, etc...
And if I try to run it python3 myscript.py every module seems to run fine, except gspread. I receive this error:
Traceback (most recent call last):
File "z_schedule.py", line 3, in <module>
from z_database import *
File "/home/pi/Projects/InstaPy/z_database.py", line 3, in <module>
import gspread, gspread_formatting
ModuleNotFoundError: No module named 'gspread'
I'm running python3 and I installed gspread both with pip and pip3. I also installed oauth2 in the same way.
My code used to work great until I updated my Raspberry, InstaPy and Python 3. Somebody knows how to fix it? Thanks.
Try this:
pip3 install gspread
and run the script again. I hope it helps to solve the problem
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.
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.