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

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.

Related

Installed module via pip, still get ModuleNotFoundError

I'm trying to use w3af to start doing some routine security testing on a webapp that I'm using. Install instructions recommend cloning a git repo, then running the python code and seeing what dependencies are unmet then installing them. My first run yielded:
ModuleNotFoundError: No module named 'ConfigParser
OK, no problem, right?
$ pip install ConfigParser
Collecting ConfigParser
Downloading configparser-5.2.0-py3-none-any.whl (19 kB)
Installing collected packages: ConfigParser
Successfully installed ConfigParser-5.2.0
Mission accomplished, let's try again!
$ ./w3af_console
Traceback (most recent call last):
File "./w3af_console", line 12, in <module>
from w3af.core.controllers.dependency_check.dependency_check import dependency_check
File "/Users/westonx/bin/w3af/w3af/core/controllers/dependency_check/dependency_check.py", line 26, in <module>
from w3af.core.data.db.startup_cfg import StartUpConfig
File "/Users/westonx/bin/w3af/w3af/core/data/db/startup_cfg.py", line 22, in <module>
import ConfigParser
ModuleNotFoundError: No module named 'ConfigParser'
Hmmm. Could swear we took care of that. Let's run pip (maybe pip3?) again to be sure?
$ pip3 install ConfigParser
Requirement already satisfied: ConfigParser in /Users/westonx/.pyenv/versions/3.8.2/lib/python3.8/site-packages (5.2.0)
Seems good. Let's check to see if the import path includes that directory:
$ python -c "import sys; print('\n'.join(sys.path)); import ConfigParser;"
/Users/westonx/.pyenv/versions/3.8.2/lib/python38.zip
/Users/westonx/.pyenv/versions/3.8.2/lib/python3.8
/Users/westonx/.pyenv/versions/3.8.2/lib/python3.8/lib-dynload
/Users/westonx/.pyenv/versions/3.8.2/lib/python3.8/site-packages
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'ConfigParser'
So... we know the sys.path includes the directory pip says the module is installed in, but when we import it, python insists it's not there.
configparser-5.2.0.dist-info and configparser.py are indeed in my ~/.pyenv/versions/3.8.2/lib/python3.8/site-packages directory, so it doesn't look like pip telling me something that's not true. But it sure looks like python is.
I'm using pyenv on MacOS 10.14, not sure if that makes a difference. Anyone have ideas of what next steps should be?
ConfigParser is a built in library in Python, but its name was changed to configparser in Python 3. It appears like w3af is still using Python 2 (I found this check that actively states it, but you never even got that far). So, to run this code, you need to run it with Python 2.
There are very many (thousands) of python3 compatibility issues with the w3af codebase. The ConfigParser issue is just the first one you hit - the codebase is full of references to outdated / unmaintained libraries, and has no support for python3 byte strings vs. unicode strings (b"" vs ""), which are used throughout the codebase.
There is a w4af project on Github, where someone has made the effort to port all the w3af code to python3, but you didn't hear that from me.

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

Wagtail Tinymce - ModuleNotFoundError: No module named 'wagtail.wagtailadmin'

I'm trying to install the package "wagtailtinymce" already downloaded it, however, the repository tutorial is completely bad. I do not know if it's because of some update or something. I'm using the latest version of wagtail and I already have a project created (obvious).
The error is in every import the package tries to make, and since I'm starting in Django and Wagtail, I do not know what to do. I have not been able to migrate the application yet because of this error.
File "/mnt/sda3/Development/Projetos/blog-wagtail/env/lib/python3.7/site-packages/wagtailtinymce/wagtail_hooks.py", line 37, in <module>
from wagtail.wagtailadmin.templatetags.wagtailadmin_tags import hook_output
ModuleNotFoundError: No module named 'wagtail.wagtailadmin'
File "/mnt/sda3/Development/Projetos/blog-wagtail/env/lib/python3.7/site-packages/wagtailtinymce/wagtail_hooks.py", line 29, in <module>
from django.core.urlresolvers import reverse
ModuleNotFoundError: No module named 'django.core.urlresolvers'
The import of django passed when I changed to "from django.urls import reverse" but the rest I do not know what to do, and I believe it will continue to give error every import
Looking at the documentation, https://github.com/isotoma/wagtailtinymce#wagtail-tinymce , this module is compatible with Wagtail 1.5 and currently we are in the 2.3 version.
As mentioned, the pip package for wagtailtinymce is not up to date for latest versions of wagtail.
However, the github repo of the package has a branch named wagtail40 which is compatible with the latest version.
To install, instead of using pip install wagtailtinymce, use pip install git+https://github.com/isotoma/wagtailtinymce.git#wagtail40 and following other steps mentioned in the docs should work.
Tested in Django==4.1.2 and wagtail==4.0.4

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!

cannot import Python-Twitter

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.

Categories

Resources