After installing the facebook-sdk module here, and looking at other solutions here and elsewhere, I keep getting this error:
Traceback (most recent call last):
File "facebook.py", line 1, in <module>
import facebook
File "/home/facebook/facebook.py", line 3, in <module>
graph = facebook.GraphAPI(access_token='ACCESS TOKEN HERE')
AttributeError: 'module' object has no attribute 'GraphAPI'
For this very simple python code to authenticate...
import facebook
graph = facebook.GraphAPI(access_token='ACCESS TOKEN HERE')
print 'Workinnnn'
It says my module is installed and up to date, and I have installed both within (as suggested) a virtualenv and outside, and still get the error. I also definitely HAVE the module in usr/local/lib/python etc. dist packages... and it contains the class GraphAPI
Has anyone got a suggestion either:
1) What might be going wrong?
2) What to try to fix it? UNinstall something?
3) If there is another way other than pip to install the module... I don't normally use pip (but definitely have it installed and installed facebook-sdk from it) so if there's another way then I'd like to try...
Cheers :/
Solution = don't name your script the same as your module.
I'm an idiot, sigh...
Related
I have tried using import pygame_textinput to call the pygame_textinput module. It doesn't work though. I got it from here.
Which was provided by another Stack Overflow page to get information about the pygame_textinput module as such:
How to create a text input box with pygame?
Just in case, I have tried getting it from the net as it is stated to be a third-party module but to no avail. I wrote the code in python shell as such:
import pygame_textinput
And got error message as such:
Traceback (most recent call last):
File "<pyshell#15>", line 1, in module
import pygame_textinput
ImportError: No module named pygame_textinput
Help? (PS. The word module in the error message second line is actually covered in < >. I deleted it as couldn't show.
Did you install it ? https://pypi.org/project/textinput/
pip install pygame_textinput
guide how to install pip: https://pip.pypa.io/en/stable/installing/
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
Using Spotipy and am attempting to 'current_user_recently_played'
token = util.prompt_for_user_token(username, scope = scope, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
sp = spotipy.Spotify(auth = token)
saved = sp.current_user_saved_tracks()
print(saved)
recent = sp.current_user_recently_played()
print(recent)
sp.current_user_saved_tracks() runs just fine, sp.current_user_recently_played() apparently doesn't exist even though it is clearly in the documentation https://spotipy.readthedocs.io/en/latest/#more-examples.
Running - v2.4.4 - January 4, 2017
Thanks ahead of time.
Traceback (most recent call last):
File "C:\Users\Martin\Google Drive\Python\Spotify\try_req.py", line 19, in <module>
recent = sp.current_user_recently_played()
AttributeError: 'Spotify' object has no attribute 'current_user_recently_played'
You're going to have to get the code manually. The installation via pip is outdated.
Navigate to where you installed Spotipy (for me it was C:\Users\[myName]\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\spotipy), open client.py and replace the code with the newer code found here.
This is due to the outdated version on PyPi, as Mangohero1 already pointed out. The following method is probably easier than manually changing code.
You can install the latest code like this:
pip install git+https://github.com/plamere/spotipy.git --upgrade
(source)
I recently started out with python and i'm right now looking to do an app that shows my Twitter feed. So I downloaded a module(not sure if its called that) called Python-Twitter and installed it. But now everytime I try to import it I just get this error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import twitter
File "build\bdist.win32\egg\twitter.py", line 38, in <module>
File "C:\Python27\lib\site-packages\requests_oauthlib-0.4.0-py2.7.egg\requests_oauthlib\__init__.py", line 1, in <module>
from .oauth1_auth import OAuth1
File "C:\Python27\lib\site-packages\requests_oauthlib-0.4.0-py2.7.egg\requests_oauthlib\oauth1_auth.py", line 4, in <module>
from requests.utils import to_native_string
ImportError: cannot import name to_native_string
Does anyone know what I might have done wrong with the install or something? Thx
In my case installing requests-oauthlib fixed it
sudo pip install requests-oauthlib
This is because of requests version.
requests.utils.to_native_string is available since requests 2.0.0
So just update requests:
pip install -U requests
See more details here on another thread
This sounds like an issue with your install. The method to_native_string should be defined in the requests\utils.py in your Python install.
I'm on Ubuntu, and installed the Twitter module, and can import it without any errors. When I look in my install, in /usr/lib/python2.7/dist-packages/requests/utils.py, there is a to_native_string method defined there.
The implication from the error you're getting is that in your installation, there is either no utils.py, or, if there is, it does not contain that method.
I would recommend checking your install to see if that is the case. If it is indeed missing, I would recommend axing your install and reinstalling. You might want to try a virtualenv environment instead, so it can act as a sandbox (in that case you can leave your current install as is, as long as it is intact enough to run virtualenv and pip).
If utils.py is actually there and does contain a method with that name, I would recommend running a debugger such as pudb or pdb (pudb isn't built in, but it's more full featured), and step through the import to see if that sheds any additional light.
I am trying to follow the example on page 5 of the book: Mining the Social Web, from O'Reilly. I am coming across the following error:
>>> import twitter
>>> twitter_api = twitter.Twitter(domain="api.twitter.com", api_version='1')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'Twitter'
What might be going on?
Check the value of twitter.__file__ (after you've imported twitter). My guess is either you somehow got a broken version of twitter, or you've created a file called twitter.py in the same directory you're running from that's blocking the installed module from loading.
If twitter.__file__ looks good (points to where your installed modules should be instead of the local dir), try easy_install -U twitter to reinstall it.
Works for me. I installed twitter through easy_install, which installed the latest version (1.6.1). dir(twitter) also lists Twitter here.
You could remove the twitter package from site-packages and try reinstalling again.