I'm trying to use scss with Flask and get it to auto-compile.
I've tried using Flask-Scss — unfortunately, when I set it up, I get Scanning acceleration disabled (_speedups not found)! errors, and no CSS file. Anyone know how to fix this, or get it to generate CSS files?
The error results from an error in the installation process. If you install through pip on an Ubuntu system and you get this warning:
==========================================================================
WARNING: The C extension could not be compiled, speedups are not enabled.
Plain-Python installation succeeded.
==========================================================================
Then you should make sure you have the libpcre3-dev library pre-installed (this is the module that contains pcre.h, the module that the C-installation fails on):
apt-get install libpcre3-dev
After doing this, re-install Flask-Scss:
pip install Flask-scss --force-reinstall -I
After restarting the Flask server, the error should now be a thing of the past.
But, please note
Even though the above will solve the problem of the _speedups not found error showing up, there is another likely reason for your files not getting compiled. If you have code like this:
app = Flask(__name__)
from flask.ext.scss import Scss
Scss(app, static_dir='static', asset_dir='assets')
...
if __name__ == "__main__":
app.run(debug=True)
, and you are not setting debug anywhere else, then you should make sure to put
app.debug = True
before the invocation of the Scss object:
app.debug = True
Scss(app, static_dir='static', asset_dir='assets')
Happiness! That should do the trick for getting your .scss files to compile every time you load a page in debug mode.
Related
So I'm having a problem for quite some time which I cannot get solved. Basically I took over a project which uses Poetry for package managing (It is a Django project). Adding packages with 'poetry add' and then installing them via 'poetry install' all works fine locally (I use a Docker container). But when pushing the changes to my server and then running 'poetry install' it says the packages are already installed. But when running the Django application, I get an internal server error saying the package doesn't exist. An example is given with the 'openpyxl' package.
pyproject.toml
...
[tool.poetry.dependencies]
openpyxl = "^3.0.10"
...
poetry.lock
...
[[package]]
name = "openpyxl"
version = "3.0.10"
description = "A Python library to read/write Excel 2010 xlsx/xlsm files"
category = "main"
optional = false
python-versions = ">=3.6"
[package.dependencies]
openpyxl = {version = ">=2.6.0", optional = true, markers = "extra == \"xlsx\""}
[package.extras]
all = ["markuppy", "odfpy", "openpyxl (>=2.6.0)", "pandas", "pyyaml", "tabulate", "xlrd", "xlwt"]
cli = ["tabulate"]
html = ["markuppy"]
ods = ["odfpy"]
pandas = ["pandas"]
xls = ["xlrd", "xlwt"]
xlsx = ["openpyxl (>=2.6.0)"]
yaml = ["pyyaml"]
openpyxl = [
{file = "openpyxl-3.0.10-py2.py3-none-any.whl", hash = "sha256:0ab6d25d01799f97a9464630abacbb34aafecdcaa0ef3cba6d6b3499867d0355"},
{file = "openpyxl-3.0.10.tar.gz", hash = "sha256:e47805627aebcf860edb4edf7987b1309c1b3632f3750538ed962bbcc3bd7449"},
]
...
error:
Anyone experienced with Poetry who can help me with this?
I'm making an educated guess on few ideas you can try (without knowing more about the problem/context). For starters:
when running / starting your app, are you using poetry run... / poetry run python... ? I'm listing this one first, since it seems like the py environment isn't accessing the installed libs. would like to know the cmd "when running the Django application"
on the server, you can try to remove the lock file and re-run poetry lock, poetry install to have a 'fresh start'. The lock file you provided is the one from the server?
how do you use Docker, is this only on local? do you use Docker on the server as a running container? You can try dockerizing your app, and as part of the Dockerfile you copy pyproject.toml/poetry.lock files have docker RUN poetry cmds to install your deps.
again, these are shots in the dark. Some areas that can use some more understanding/detail are (a) how you start up Django app and (b) how you use Docker. If you're looking at point #3, I can elaborate on a solution for you. I've worked with quite a bit of docker+poetry apps/services.
We are using command prompt c:\gcloud app deploy app.yaml, but get the following error:
Running "python3 -m pip install --requirement requirements.txt --upgrade --upgrade-strategy only-if-needed --no-warn-script-location --no-warn-conflicts --force-reinstall --no-compile (PIP_CACHE_DIR=/layers/google.python.pip/pipcache PIP_DISABLE_PIP_VERSION_CHECK=1)"
Step #2 - "build": /layers/google.python.pip/pip/bin/python3: Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')
Step #2 - "build": Done "python3 -m pip install --requirement requirements.txt --upgr..." (34.49892ms)
Step #2 - "build": Failure: (ID: 0ea8a540) /layers/google.python.pip/pip/bin/python3: Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__')
Step #2 - "build": --------------------------------------------------------------------------------
Step #2 - "build": Running "mv -f /builder/outputs/output-5577006791947779410 /builder/outputs/output"
Step #2 - "build": Done "mv -f /builder/outputs/output-5577006791947779410 /builder/o..." (12.758866ms)
Step #2 - "build": ERROR: failed to build: exit status 1
Finished Step #2 - "build"
ERROR
ERROR: build step 2 "us.gcr.io/gae-runtimes/buildpacks/python37/builder:python37_20211201_3_7_12_RC00" failed: step exited with non-zero status: 145
Our Requirements.txt is as below. We are currently on Python 3.7 standard app engine
firebase_admin==3.0.0
sendgrid==6.9.3
google-auth==1.35.0
google-auth-httplib2==0.1.0
jinja2==3.0.3
MarkupSafe==2.0.1
pytz==2021.3
Flask==2.0.2
twilio==6.46.0
httplib2==0.20.2
requests==2.24.0
requests_toolbelt==0.9.1
google-cloud-tasks==2.7.1
google-cloud-logging==1.15.1
googleapis-common-protos==1.54.0
Please help.The above code was working well before updating the requirements.txt file. We tried to remove gunicorn to allow the system pickup the latest according to documentation here.
We have a subdirectory structure that stores all the .py files in controllers and db definitions in models. Our main.py has the following -
sys.path.append(os.path.join(os.path.dirname(__file__), '../controllers'))
sys.path.append(os.path.join(os.path.dirname(__file__), '../models'))
Does anyone know how to debug this error - Error while finding module specification for 'pip' (AttributeError: module '__main__' has no attribute '__file__'). What does this mean?
The release 60.3.0 of setuptools has a bug causing the above AttributeError, see : https://github.com/pypa/setuptools/issues/3002
It has been yanked by Pypi since then:
Yanked files are always ignored, unless they are the only file that matches a version specifier that "pins" to an exact version using either == (without any modifiers that make it a range, such as .*) or ===. Matching this version specifier should otherwise be done as per PEP 440 for things like local versions, zero padding, etc.
Source: https://www.python.org/dev/peps/pep-0592/
What you can do as of now is pass the version of the setuptools package explicitly, to use for example version 60.2.0 or 60.3.1.
I had the same issue when deploying a Google Cloud Function. The error
cloud function Error while finding module specification for 'pip' (AttributeError: module 'main' has no attribute 'file'); Error ID: c84b3231
appeared after commenting out some packages in the requirements.txt, but that was nothing important and likely did not cause it. I guess that it is more a problem of an instability in Google Storage, since that same Cloud Function I was working on had lost its archive already some time before, all of a sudden, out of nowhere, showing:
Archive not found in the storage location cloud function
and I did not delete or change anything that might explain this, as Archive not found in the storage location: Google Function would suggest. Though that answer has one very interesting guess that might explain at least the very first time the "Archive not found" error came up and thus made the CF instable: I might have changed the timezone city of the bucket during browsing the Google Storage. It is too long ago, but I know I browsed the GS, therefore, I cannot exclude this. Quote: "It [the Archive not found error] may occurr too if GCS bucket's region is not matched to your Cloud function region."
After this "Archive not found" crash, I manually added main.py and requirements.txt and filled them again with code from the backup. This worked for some time, but there seems to be some general instability in the Google Storage. Therefore, always keep backups of your deployed scripts.
Then, after getting this pip error of the question in that already instable Cloud Function, waiting for a day or two, Google Function again showed
Archive not found in the storage location cloud function
If you run into this pip error in a Cloud Function, you might consider updating pip in the "requirements.txt" but if you are in such an unstable Cloud Function the better workaround seems to be to create a new Cloud Function and copy everything in there.
The pip error probably just shows that the source script, in this case the requirements.txt, cannot be run since the source code is not fully embedded anymore or has lost some embedding in the Google Storage.
Or you give that Cloud Function a second chance and edit, go to Source tab, click on Dropdown Source code to choose Inline Editor and add main.py and requirements.txt manually (Runtime: Python).
By installing the previous version 60.2.0 of setuptools before installing pip-tools helped me get it running.
pip install setuptools==60.2.0
Your setuptools version is likely to be yanked:
https://pypi.org/project/setuptools/60.3.0/
Not sure how to fix that without a working pip though.
Setuptools 60.3.1 is out now. GitHub Link here.
Everytime I deploy my app, I delete all the stuff in the folder and I load my Github app project (with the .spec) before running buildozer -v android release.
Now I encounter this error: toolchain.py: error: the following arguments are required: --package
but I only changed my python code. How is it possible that changing python stuff makes my .apk creation crash ? What could I try to debug this ?
Found it, you can begin a line with # to make a commentary but you can't do put it following a useful line.
When I try to install anything with Pip, it gives me the "Fatal error in launcher:" error. That wouldn't be too bad, since I know how to update Pip differently. However, the same error occurs when I try to run the "flask run" command.
I'm using Windows 10, Python 3.8.2 and I have previously set the FLASK_APP variable to flaskblog.py. This is its content:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def hello():
return "Hello World!"
Since you haven't posted the error clearly, if Fatal error in launcher: Unable to create process using ‘”‘ is your error,
then you might want to update pip using python -m pip install --upgrade pip and try installing your package again using python -m pip install <pkg-name>. You should get it working.
if the error persists after the above mentioned steps, the try importing pip in your python console(pull up your terminal and type python then type import pip) and try pip.main([‘install’,’<pkg-name>’]) in the console.
Hope this helps.
referred from here
Edit
Alternatively, you can run your flask app by adding app.run() in your script.
Like:
if __name__ == __main__:
app.run()
and then in the terminal, run python -m flaskblog.py.
Note: if you want to run your app in debug mode, consder giving debug = True to app.run().
I'm trying to setup Django on an internal company server. (No external connection to the Internet.)
Looking over the server setup documentation it appears that the "Running Django on a shared-hosting provider with Apache" method seems to be the most-likely to work in this situation.
Here's the server information:
Can't install mod_python
no root access
Server is SunOs 5.6
Python 2.5
Apache/2.0.46
I've installed Django (and flup) using the --prefix option (reading again I probably should've used --home, but at the moment it doesn't seem to matter)
I've added the .htaccess file and mysite.fcgi file to my root web directory as mentioned here.
When I run the mysite.fcgi script from the server I get my expected output (the correct site HTML output). But, it won't when trying to access it from a browser.
It seems that it may be a problem with the PYTHONPATH setting since I'm using the prefix option.
I've noticed that if I run mysite.fcgi from the command-line without setting the PYTHONPATH enviornment variable it throws the following error:
prompt$ python2.5 mysite.fcgi
ERROR:
No module named flup Unable to load
the flup package. In order to run
django as a FastCGI application, you
will need to get flup from
http://www.saddi.com/software/flup/
If you've already installed flup,
then make sure you have it in your
PYTHONPATH.
I've added sys.path.append(prefixpath) and os.environ['PYTHONPATH'] = prefixpath to mysite.fcgi, but if I set the enviornment variable to be empty on the command-line then run mysite.fcgi, I still get the above error.
Here are some command-line results:
>>> os.environ['PYTHONPATH'] = 'Null'
>>>
>>> os.system('echo $PYTHONPATH')
Null
>>> os.environ['PYTHONPATH'] = '/prefix/path'
>>>
>>> os.system('echo $PYTHONPATH')
/prefix/path
>>> exit()
prompt$ echo $PYTHONPATH
Null
It looks like Python is setting the variable OK, but the variable is only applicable inside of the script. Flup appears to be distributed as an .egg file, and my guess is that the egg implementation doesn't take into account variables added by os.environ['key'] = value (?) at least when installing via the --prefix option.
I'm not that familiar with .pth files, but it seems that the easy-install.pth file is the one that points to flup:
import sys; sys.__plen = len(sys.path)
./setuptools-0.6c6-py2.5.egg
./flup-1.0.1-py2.5.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sy
s.path[p:p]=new; sys.__egginsert = p+len(new)
It looks like it's doing something funky, anyway to edit this or add something to my code so it will find flup?
In your settings you have to point go actual egg file, not directory where egg file is located. It should look something like:
sys.path.append('/path/to/flup/egg/flup-1.0.1-py2.5.egg')
Try using a utility called virtualenv. According to the official package page, "virtualenv is a tool to create isolated Python environments."
It'll take care of the PYTHONPATH stuff for you and make it easy to correctly install Django and flup.
Use site.addsitedir() not os.environ['PYTHONPATH'] or sys.path.append().
site.addsitedir interprets the .pth files. Modifying os.environ or sys.path does not. Not in a FastCGI environment anyway.
#!/user/bin/python2.6
import site
# adds a directory to sys.path and processes its .pth files
site.addsitedir('/path/to/local/prefix/site-packages/')
# avoids permissions error writing to system egg-cache
os.environ['PYTHON_EGG_CACHE'] = '/path/to/local/prefix/egg-cache'
To modify the PYTHONPATH from a python script you should use:
sys.path.append("prefixpath")
Try this instead of modifying with os.environ().
And I would recommend to run Django with mod_python instead of using FastCGI...