That's my very first question here, please don't eat me! I am totally newbie, I try to write a flask app using flask-dance for OAuth reason. Seems I do something stupid, because when I try to import SQLAlchemyBackend class from flask_dance.consumer.backend.sqla Python returns
ModuleNotFoundError: No module named 'flask_dance.consumer.backend'
Can you tell me please what exactly I do wrong?
I use flask-dance[sqla] version for SQLAlchemy db. First I installed basic version without SQLAlchemy support, then I uninstalled it and installed current one (all inside the venv). Is it possible that that affected the F-D functionality and its own modules and submodules scheme?
I have no idea how to fix that problem and where to go. Google doesn't help neither.
What I see in the trackback is:
Traceback (most recent call last): File "c:\users\igor\envs\2do2\lib\site-packages\flask\cli.py", line 235, in locate_app
__import__(module_name) File "C:\Users\igor\projects\gp\2do2\app\app.py", line 8, in <module>
from flask_dance.consumer.backend.sqla import SQLAlchemyBackend ModuleNotFoundError: No module named 'flask_dance.consumer.backend'
In Flask-Dance 1.4.0, "backends" were renamed to "storages", since the word "backend" means something different in the context of web development. This change was backwards-compatible in 1.4.0, but the backwards-compatibility features were dropped in Flask-Dance 2.0.0.
To make this work in Flask 2.0 and above, just replace the word "backend" with the word "storage" everywhere you see it. For example, this line of code:
from flask_dance.consumer.backend.sqla import SQLAlchemyBackend
becomes this instead:
from flask_dance.consumer.storage.sqla import SQLAlchemyStorage
If you see any references to "backends" in the current documentation, please let me know! They should all be "storages" now.
Related
I'm using virtualenv with my application, and I've installed gdata, jira, and gspread using env/bin/pip install <lib name> in terminal under my project folder. I'm following the documentation from the Google API but it is not working?
In the documentation, in order to do error handling you need to do:
from gdata import errors
And in order to create an instance of the Drive API service (in order to later on create a file) you need to do:
from gdata.discovery import build
However the files are different, there is no "discovery" or "errors" and when I run env/bin/python run.py I get this error:
Traceback (most recent call last):
File "run.py", line 3, in <module>
from gdata import errors
ImportError: cannot import name errors
(same with discovery)
I thought that maybe they mean from apiclient import errors literally in the documentation, so I tried pip installing apiclient and replacing gdata with apiclient but it still does not work.
I downloaded the gdata.zip file and unzipped it and looked through the sample code (especially for spreadsheet since that's what I'm trying to create) and they take a very different approach than the documentation and I'm very confused. My goal is to use their API to just create a spreadsheet from the code, but I do not plan on using their API to edit the spreadsheet itself, I plan on using gspread (Github).
I've done a lot of research and I've been directed to a lot of different places and I might have perhaps mixed up the code? Does anyone know what I did wrong/have a fix? A huge thanks in advance.
This kind of import error is usually caused by the user installing another module of the same name. Do you by any chance have a gdata.py somehwere on your Python path?
You can verify whether this is causing the issue by:
import gdata
print gdata.__file__
This tells you where the interpreter is loading the code from.
When i compile s3cmd, I found Versioning module is missing, stacktrace as:
Traceback (most recent call last):
File "./s3cmd", line 1983, in <module>
from S3.S3 import S3
File "/home/chutong/s3cmd.svn/S3/S3.py", line 29, in <module>
from Versioning import Versioning
ImportError: No module named Versioning
I tried to check online and there is not much resource? Can someone please help? Thanks
I just checked the source for s3cmd on github. It appears it no longer imports this module nor does it contain a module named Versioning in its code tree.
Without more information I can't tell, but what I would suspect is you have a version mismatch, perhaps one version installed in your Python environment and another one locally.
It's a bit odd that it's raising the exception from an SVN directory, but like I say, will need more information about your execution environment to make any headway. Things like current directory, a dump of sys.path, that sort of thing.
But if it's possible, you might try updating the installed version and trying again. Looks like the library has had some significant updates since the version you appear to be using.
I have been trying to import modules into Ninja IDE for python. These are modules that I have working on the terminal (numpy, scipy, scitools, matplotlib, and mpl_toolkits), but will not run correctly in Ninja.
First I was only getting the message No module named ____. I checked sys.path and found that the path was within the application
/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7 was a typical path. I tried changing the path,but it doesn't seem to do anything to sys.path even after restarting the ide.
But I wanted the path to refer to where the modules are stored (which is /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages). I was able to get numpy and scipy to work as well as parts of mpl_toolkits by adding the contents of my path to the folders that sys.path gave. However, I still can't get fully functioning modules within the ninja ide interpreter. I'll give some examples below of what happens when I import certain modules.
import matplotlib.pyplot
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/matplotlib/__init__.py", line 106, in <module>
ImportError: No module named sysconfig
import mpl_toolkits
from mpl_toolkits.mplot3d import axes3d
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/mpl_toolkits/mplot3d/__init__.py", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/mpl_toolkits/mplot3d/axes3d.py", line 14, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/matplotlib/__init__.py", line 106, in <module>
ImportError: No module named sysconfig
Thanks for the help. I apologize, I am very new to programming, but I did put in about a day and a half of research before posting here.
That's strange as the sysconfig module is a part of Python 2.7 standard library.
Are you sure that Ninja is using the right Python version? Try running:
import sys
print sys.version_info
from Ninja, to see which Python version it is actually using.
I know this question is a few months old, but I wanted to post my solution in case others find it useful. I had a very similar problem, and had a lot of trouble finding a quick workable solution anywhere.
My somewhat roundabout solution was to simply create a virtualenv folder with the version of numpy I wanted, and then pointed the "virtualenv" property for NinjaIDE project to that folder. I restarted NinjaIDE and boom, instantly worked.
To set the virtualenv property for your project via the GUI, go to the Project menu:
Project > Open Project Properties > Project Execution,
and you should see a variable called "Virtualenv Folder". Point that to the folder for your virtualenv, and it should work. (May need to restart NinjaIDE.) This worked for me, NinjaIDE version 2.2 under Ubuntu 12.04.
One quick note: I actually didn't use virtualenv exactly -- I had to use a "conda env," since I am using the Anaconda distribution, and apparently it is not well-tested with virtualenv yet. (I actually got a warning when I went to easy_install virtualenv. Hadn't seen that before.)
Either way, this stackoverflow question has some nice pointers to virtualenv tutorials: Comprehensive beginner's virtualenv tutorial?
Good luck!
I was having a similar problem trying to import a module from /home/paul/lib/python using the console of the Ninja-IDE. I found out that /home/paul/lib/python didn't appear in syspath when checking in the console of the Ninja-IDE. But it did in the terminal!
By starting the Ninja-IDE from the terminal, /home/paul/lib/python was in syspath when checking in the console of the Ninja-IDE. I was now able to import the module I needed.
I hope this might be of some help. If not to ebris1 than maybe to others.
I'm at exercise 50 of lpthw this is the link.
And after having downloaded the lpthw.web framework in a very messy way.
I continued the exercise by writing a .py file.
import web
urls = ('/', 'index')
app = web.application(urls, globals())
class index:
def GET(self):
greeting = "Hello World"
return greeting
if __name__ == "__main__":
app.run()
but i got this error:
Traceback (most recent call last):
File "bin\app.py", line 1, in <module>
import web
File "c:\Python31\lib\site-packages\web\__init__.py", line 14, in <module>
import utils, db, net, wsgi, http, webapi, httpserver, debugerror
ImportError: No module named utils
What is the problem caused by,
I suspect it is the very messy way with wich I installed lpthw.web (I got a lot of errors, but tried multiple ways multiple times.)
Thank you in advance!
If anybody needs more info comment so I can edit.
I think you forgot to read the setup instructions. This learning guide is not python3 compatible:
Exercise 0: The Setup
You should follow these instructions as exactly as possible. For
example, Mac OSX computers already have Python 2, so do not install
Python 3 (or any Python).
Make sure you install Python 2 not Python 3.
Warnings For Beginners
A programmer may try to get you to install Python 3 and learn that. You should tell them, "When all of the python code on your computer is Python 3, then I'll try to learn it." That should keep them busy for about 10 years.
Remove python3 from your system and install python2.7 to allow this tutorial to work when you install suggested packages.
Otherwise, find another tutorial that is using examples from libararies that are python3 compatable. Not everything is updated as of right now. Many people stick to python2.7 for this reason.
As the tutorial state, you can try installing using easy_install or pip from the command line it would be easy_install lpthw.web or pip install lpthw.web
Also note that you need to properly reference application
this app = application(urls, globals()) should be
app = web.application(urls, globals())
note the ^^^ part.
Also if you are interested in python micro-web-frameworks I recommend bottle.py, it doesn't need to be installed its just a single python file called bottle.py
Update
I managed to recreate the problem using python3, so jdi was right, the problem here is that python3 isn't backwards compatible with python2, some python2 complaint applications won't properly run under python3 and vice-versa.
In this case python3 doesn't seem to support relative imports within package, did find this http://www.python.org/dev/peps/pep-0328/ which was kind of interesting.
exert from the pep:
For the second problem, it is proposed that all import statements be absolute by default (searching sys.path only) with special syntax (leading dots) for accessing package-relative imports.
so lpthw.web tries to import relative packages but it simply can't.
which is why we get ImportError: No module named utils since utils is relative module within the package.
even if it could loaded it, it will stumble with other non-backwards compatibility issues, just trying to import utils within the package we get
>>> import utils
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "utils.py", line 75
except KeyError, k:
^
SyntaxError: invalid syntax
which is related to this pep http://www.python.org/dev/peps/pep-3110/ which states different syntax to the except statement.
As you can see it will be a major hurdle trying to migrate this package to python3 so much so thats its better to leave it to the developers, this goes for the many many packages out there, why is python3 so different from python2, well mainly because they wanted to patch the language as much as possible ...
For the time being stick to python2, eventually most packages will be migrated to python3.
While reading the code for django/forms/widgets.py, I saw:
from util import flatatt
To dig deeper, I tried to import the util module in a Python shell in my terminal, but I got an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named util
This left me confused. What is wrong?
Django is (ab?)using Python's import system in order to import something from django.forms.util. Import that module instead.
In python, you get this ImportError:
Traceback (most recent call last):
File "b.py", line 3, in <module>
from util import flatatt
ImportError: No module named util
Some programmer out there created a library for your python script to use. Your program was unable to find that library. So the interpreter tells you that it can't be found. You have a few options. Either you have to define the library and functionality yourself, or you'll have to review the instructions and source code of the program you are trying to run, and try to figure out what is broken to prevent the library from being included. Or the final option is to remove any usage of that library in the current script.
You can define the module yourself like this:
Put this in util.py in the same directory as your widgets.py file.
def flatatt(prompt):
print("ok")
If you define that, you will get a different error, the script will import your library, and find that method, but then will do the wrong thing, because the programmer who designed that code probably had some other functionality in mind.
You need to figure out what you did wrong, or what the original programmer did wrong, or how your specific system is different to cause this to work.
You can learn more about what I've described above here, by rolling your own python modules: Python: How to import other Python files
Often times these sorts of bugs are barriers to entry, the original developers don't want programmers who don't know the difference between an integer and a module using the software. So little problems like this are added, to help encourage you that you need to develop a better understanding of the source code under the hood. It's like a mechanic helping everyone become better mechanics by swapping the wires on the distributor cap. It isn't going to work until you swap them back rightly.
from django.forms.utils import flatatt
It worked with django 1.11 version, and may work with 1.8 through 1.10