cannot import Python-Twitter - python

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.

Related

Import discord.py returns the error " ModuleNotFoundError: aiohttp”

I am working on a project in which you will need to unpack the archive with all the data and everything will work, without installing packages by the user. I came to the creation of a discord bot, but it gives an error, I do not understand what is associated with it.
Traceback (most recent call last):
File "path\Project Folder\bot.py", line 2, in <module>
import modules.discord
File "path\Project Folder\modules\discord\__init__.py", line 25, in <module>
from .client import Client
File "path\Project Folder\modules\discord\client.py", line 33, in <module>
import aiohttp
ModuleNotFoundError: No module named 'aiohttp'
Before that, I downloaded pythonping absolutely as well and there were no errors when importing it.
Downloaded it like this:
pip install --target="path\Project Folder\modules" pythonping
pip install --target="path\Project Folder\modules" discord.py
The folder where it was downloaded looks like this (initially it was empty):
If I change the import of the discord in the same file, and add pythonping, then everything will work without errors.
from modules.pythonping import ping
#import modules.discord
import botinfo
print(botinfo.BotTag)
At the very end, I manually downloaded the discord archive from github and put it in the modules directory, but since there is no aiohttp, ctrl+click did not redirect to it, after which I already downloaded aiohttp pip install --target="path\project folder\modules" aiohttp and ctrl+click began to go to aiohttp, but the error remained (absolutely the same).
Additional information:
python --version Python 3.8.2
pip --version pip 21.0.1
For some reason, the python version decided to change from the last to the previous one, which is why discord did not run on the NEW version, because it still took packages not from the project directory, but from the interpreter directory. I switched to an earlier version of python and it worked, then I forcibly downloaded it to the new version and it also worked.
I think running the following command might be a good idea :
pip install aiohttp

Unable to import 'flask_uploads' pylint(import-error)

I installed flask-upload module in windows 10:
pip install flask flask-wtf flask-uploads
The results were:
Successfully installed Jinja2-2.11.2 MarkupSafe-1.1.1 WTForms-2.3.1 Werkzeug-1.0.1 click-7.1.2 flask-1.1.2 flask-uploads-0.2.1 flask-wtf-0.14.3 itsdangerous-1.1.0
Then in the text editor there is an error when I import the module as shown in the screenshot. unable to import flask-uploads
After running the app.py the following are the errors in cmd:
Error: While importing "app", an ImportError was raised:
Traceback (most recent call last):
File "c:\users\seanv\onedrive\documents\web dev\##pprojects\flask\flask_uploads\myenv\lib\site-packages\flask\cli.py", line 240, in locate_app
__import__(module_name)
File "C:\Users\seanv\OneDrive\Documents\web dev\##pprojects\flask\flask_uploads\app.py", line 4, in <module>
from flask_uploads import configure_uploads, IMAGES, UploadSet
File "c:\users\seanv\onedrive\documents\web dev\##pprojects\flask\flask_uploads\myenv\lib\site-packages\flask_uploads.py", line 26, in <module>
from werkzeug import secure_filename, FileStorage
ImportError: cannot import name 'secure_filename' from 'werkzeug' (c:\users\seanv\onedrive\documents\web dev\##pprojects\flask\flask_uploads\myenv\lib\site-packages\werkzeug\__init__.py)
May someone who understands the problem help me with possible solutions or suggestions. Thank you in advance.
Your app is using Flask-Uploads.
Back in February 2020, there was an update for Werkzeug, a library which Flask and many libraries, including Flask-Uploads, is based on.
This update introduced a breaking change, as Werkzeug changed its API, ie. the import of secure_filename.
I provided a pull request to Flask-Uploads, which the maintainer accepted. But very sadly and unfortunately the maintainer did not want to provide a new package for PyPi.
So, while you could install the updated Flask-Uploads via a commit id from its GitHub repository, you cannot any longer install it from PyPi.
I asked the maintainer for a new release, I also offered my help, but no chance.
So, finally, I decided to fork the library.
Here is the new package on PyPi
https://pypi.org/project/Flask-Reuploaded/
Here is the repository
https://github.com/jugmac00/flask-reuploaded
It is a drop-in replacement. So you just have to install the new package and it just works. No need to change any imports or code in your application.

python v 2.7.13 with twilio v 6.5.2 cannot find module named urllib3 when importing Client

I'm using python version 2.7.13 and twilio version 6.5.2 and I'm trying the simple example from twilio website which begins with
from twilio.rest import Client
then goes on to send a text message to a phone number. Executing that first line within idle produces this error message:
Traceback (most recent call last):
File "C:\Users\...\send_text.py", line 1, in <module>
from twilio.rest import Client
File "build\bdist.win32\egg\twilio\rest\__init__.py", line 14, in <module>
File "build\bdist.win32\egg\twilio\http\http_client.py", line 1, in <module>
File "C:\Python27\lib\site-packages\requests-2.18.4-py2.7.egg\requests\__init__.py", line 43, in <module>
import urllib3
ImportError: No module named urllib3
I have found similar questions in this forum but the details are slightly different and the solutions do not apply to my situation.
First, check this link: https://matthewhorne.me/how-to-install-python-and-pip-on-windows-10/
Second, on your console, execute: pip install urllib3
This steps maybe can help you. Good luck.
Make sure you have installed the module using pip install urllib3 before you import it.
Thank you to Jose Moreno and Colin Ricardo.
Re-installing twilio using pip rather than easy_install was step one. Then, as suggested by Jose and Colin, the next step was to pip install urrlib3.
Turned out to be two more things that were missing, but pip installing them worked.
Then I was able to get a trial phone number from twilio and their sample send_text.py program actually worked for me!

Error during library import in Python (Windows)

I am trying to configure svn hook for email notification using mailer.py script from apache, but it always crash on import of svn libs. I try two ways of installing svn and python. I try to install everything manually using command line and use CollableNet installer that have preinstalled Python and all libs I need but result is the same.
Now I try to import one library from hole package that I need using python in command line and I have such response:
>>> import svn.core
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named svn.core
I try to fix it using:
1) import sys; sys.path.append("C:\csvn\lib\svn-python\svn")
and
2) C:\csvn\lib\svn-python\svn>python "\__init__.py" install
But it didn't help.
For now I have no package with setup.py to install it.
I spend a lot of time on this task, and going crazy a little). Please give me any suggestion how to fix it.

Scrapy ImportError: cannot import name xmlrpc_client

I'm trying to use scrape on Mac OS X EI, and I have successfully installed scrapy using
pip install scrapy
in the terminal.
After that, I met the above problem when I tried to "import scrapy" in the Pycharm:
Traceback (most recent call last):
File "/Users/ziyuan/PycharmProjects/untitled/en.py", line 1, in <module>
import scrape
File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 48, in <module>
from scrapy.spiders import Spider
File "/Library/Python/2.7/site-packages/scrapy/spiders/__init__.py", line 10, in <module>
from scrapy.http import Request
File "/Library/Python/2.7/site-packages/scrapy/http/__init__.py", line 12, in <module>
from scrapy.http.request.rpc import XmlRpcRequest
File "/Library/Python/2.7/site-packages/scrapy/http/request/rpc.py", line 7, in <module>
from six.moves import xmlrpc_client as xmlrpclib
ImportError: cannot import name xmlrpc_client
And I have tried everything from Scrapy throws ImportError: cannot import name xmlrpc_client
Specifically, when I tried the highest-voted solution, the second line
sudo rm -rf/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six*
throwed me another problem:
rm: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info: Operation not permitted
rm: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.py: Operation not permitted
rm: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.pyc: Operation not permitted
What should I do now? I have searched it in google for a long time and I really have no idea now.
A different way to deal with this problem, rather than highest-voted solution as you mentioned, is using other Python(not the system one) and virtualenv.
But why new Python? Here's an good article for the question. Reasons are easy to find.
And why virtualenv? You can get the point form here.
Furthermore, it's maybe not an good idea to use $ sudo pip (...). Please look at this.
So let's do the recommended way by one of Scrapy's contributor! Look at Mac OS X part: Using Homebrew to install new Python, updated your path variable, ...etc. Although she said using virtualenv is optional, I can only keep ImportError: blahblah.. away in my own virtual environment when using Scrapy.
After trying several solutions and attempting to work around the six 1.4.1 version, I found this worked:
sudo easy_install --upgrade six
Operation not permited means you don't have the permission to remove this. Try sudo rm instead to delete it as a Super User.
Though ideally you shouldn't rm anything from your python, try pip uninstall six instead. However you still need six so you might as well try upgrading it via pip install six --upgrade.
Note that you might have to use pip2 instead of pip because certain systems label it differently.

Categories

Resources