Good Morning!
I am a beginner in the python / flask world ... I found this template and found it complete and simple, good for beginners and with some interesting features.
I just can not run this template. It has some packages that do not install by pip (pycrypto==2.6.1, python-cloudfiles==1.7.11, python-loaders==0.2.3).
Was this a reason? Can anybody help me?
I need some help to run this template.
enter image description here
Thanks!
This project is unmaintained, please try this one instead.
For your question, flask.ext.foo is the old way to import extension and it is removed in Flask 1.0. If you want to fix it, try the methods below:
Method 1: Fix old import statements
Find these lines in application/__init__.py:
from flask.ext.cache import Cache
from flask.ext.sqlalchemy import SQLAlchemy
change them to:
from flask.cache import Cache
from flask.sqlalchemy import SQLAlchemy
Method 2: Use a virtual enviroment
Everything will be ok if you use the pinned version in the project's requirement file. Just create a virtual enviroment with virtualenv, pipenv, poetry, venv etc, activate the virtual enviroment, then install dependency from the requirements.txt file.
Related
I wanted to implement swagger in Django rest framework, for that I install django-rest-swagger and register in setting.py but while importing in url.py it show error:-
"Import "rest_framework_swagger.views" could not be resolved.
How can I use rest_framework_swagger?
You should be calling this way.
Example :
from rest_framework_swagger.views import get_swagger_view
Instead of get_swagger_view call the view you require.
There could be many reasons but the truth is you shouldn't be using a project that's read-only for over 2.5 years.
Try drf-yasg or drf-spectacular instead.
Anyway, if you installed the lib you're talking about with
pip install django-rest-swagger
it should be available in your environment. Make sure you see it in pip freeze.
I'm a beginner in Python and I have no experience with GitHub at all. I want to import the module semsimlib from the following URL: https://github.com/timvdc/semsimlib
I have looked on the internet for help on how to do this but most of it is very unclear and doesn't seem to work for me. Can anyone provide a detailed explanation on how to do this in a easy way?
It looks the repo does not provide appropriate scripts to simply install the package. There is no setup.py file and there is no distribution on pypi.
What you can do is go to site-packages folder inside your python installation or inside your virtual environment. Then run git clone https://github.com/timvdc/semsimlib. You should now be able to import semsimlib. Keep in mind that you will also have to install all the other dependencies your self one by one since there is also no requirements file.
You can also clone the repo into any folder on your computer and at the top of your script put:
import sys
sys.path.append("path/to/semsimlib/folder")
semsimlib will now be importable. However, I would try to get it to work with the first method.
I am using Pycharm, with python 3.8 and I am watching a flask tutorial for beginners. this means that I am a beginner so I might not understand every vocab or solution, however, a little research on my end will make it alright.
So the problem I am having is that I downloaded flask_sqlalchemy with the following code on the PyCharm terminal:
pip install Flask-SQLAlchemy
I thought I had been successful since the event log also said installation successful. However, when I wrote the following code:
from flask_sqlalchemy import SQLAlchemy
it reported "unresolved reference flask_sqlalchemy"
I then tried entering this in the terminal thinking it would work:
pip install -U Flask-SQLAlchemy
Nothing changed.
I tried installing SQLAlchemy to see if it would do something but it didn't.
I used the following code in the terminal:
pip install SQLAlchemy
Any ideas on how to get this to work?
Go to File -> Preferences -> Python Interpreter. Hit the plus button and install the package SQLAlchemy.
If that does not work, go to File -> Invalidate Cache.
What finally worked for me was deleting the venv folder, deleting the interpreter, and creating a new one. Make sure to enable inheritance of global packages because when you use pip3 install Flask-SQLAlchemy it installs to the default interpreter.
You really should be able to install it to your virtual environment. But I spent 3hrs on it and couldn't figure out how.
If you're still stuck, refer to "Python shows unresolved references error for valid code.
Well I'm trying to use Datastore in a personal project using the Google App Engine. Though, I can't import the datastore module, no matter how hard I try.
I've been using the online console during the whole time (in order to avoid to have to solve problems first on my PC and then on GCloud...)
So, I'm using
from google.cloud import datastore
Unfortunately, that's not working at all. The last error I have is
ImportError: No module named google.protobuf
But before I had things like Can't import Datastore.
What I did was removing the integrality of /lib, and reinstalling every dependancy with pip. Here is my requirements.txt:
# This requirements file lists all third-party dependencies for this project.
#
# Run 'pip install -r requirements.txt -t lib/' to install these dependencies
# in `lib/` subdirectory.
#
# Note: The `lib` directory is added to `sys.path` by `appengine_config.py`.
Flask==0.10
google.cloud==0.25.0
protobuf==3.3.0
(The last line was added to try to resolve the last error I got). Before having this error, I got
Also, a little clarification question: I've seen (while looking for answers) people using gcloud and some using google.cloud. What's the difference? What should I use?
Also, pip show google.cloud shows nothing.
What am I missing?
Thank you
Well, if anyone is wondering, here's how I solved the problem. What fixed it was changing the Flask version to 0.12 (don't know why, but that's what happened).
I deleted lib to be sure I was starting from scratch. Then, I used this requirements.txt file:
Flask==0.12
google-cloud==0.25.0
click==5.1
(click is needed by Flask 0.12).
I have a Flask project which I've put the flask module (version 0.9) directly beside my app.py file. I've done this so that I can bundle everything into a version control repository that won't require anyone else using it to install additional Python modules.
I want to use flask-login so I've tried to manually install it by downloading the latest version and putting the flask_login.py file in my "local" flask/ext/ directory. However, while I can import flask and import flask.ext, I am unable to import flask.ext.login with Python throwing ImportError: No module named flask.ext.login. import flask.ext.flask_login throws an import error as well.
Is there something I have to do differently if Flask and it's extensions are local to the app.py?
The solution is to put the flask_login.py file in the same directory as my app.py file. No modification of the flask/ext/__init__.py file is necessary.
The flask.ext module is intended only as a an extension importer, not a repository for installed extensions. Based on the import path, I thought the flask/ext folder was where extensions were to be copied. This was incorrect. Extensions simply need to be somewhere on the python path.
Python doesn't throw the exception in your case, this Flask module is responsible for modifying the standard import hook in the ext folder:
https://github.com/mitsuhiko/flask/blob/master/flask/exthook.py
So, I don't think putting flask_login.py into flask/ext is the right way to use extensions in Flask. The documentation recommends to use pip install flask-login or python setup.py install. After that you can do:
import flask_login
If you still want to do it manually, remove the setup() call from ext/__ init__.py.
It probably has a good reason why the Flask guys did it this way though :-)
Right, but the point was to manually install everything so it could be self-contained in a version control repository that won't require additional installs. I've looked at the setup.py file but can't determine how it achieves the installation. – Soviut Oct 25 at 10:06
Why not use virtualenv to achieve this? You can push your env to source control as well, although that's not normal usage.
See: http://www.virtualenv.org/en/latest/