I am using webpush in my Django application. Following the recommendation it works well locally.
When I push the code to my host, it gives me this mistake ModuleNotFoundError: No module named 'webpush'.
Application does not work.
Error log:
2023-02-15 07:51:15,780: Error running WSGI application
2023-02-15 07:51:15,780: ModuleNotFoundError: No module named 'webpush'
2023-02-15 07:51:15,780: File "/var/www/www_……….._pl_wsgi.py", line 30, in
2023-02-15 07:51:15,781: application = get_wsgi_application()
2023-02-15 07:51:15,781:
2023-02-15 07:51:15,781: File "/home/……/.virtualenvs/venv/lib/python3.10/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2023-02-15 07:51:15,781: django.setup(set_prefix=False)
2023-02-15 07:51:15,781:
2023-02-15 07:51:15,782: File "/home/……/.virtualenvs/venv/lib/python3.10/site-packages/django/init.py", line 24, in setup
2023-02-15 07:51:15,782: apps.populate(settings.INSTALLED_APPS)
2023-02-15 07:51:15,782:
2023-02-15 07:51:15,782: File "/home/……./.virtualenvs/venv/lib/python3.10/site-packages/django/apps/registry.py", line 91, in populate
2023-02-15 07:51:15,782: app_config = AppConfig.create(entry)
2023-02-15 07:51:15,782:
2023-02-15 07:51:15,782: File "/home/…../.virtualenvs/venv/lib/python3.10/site-packages/django/apps/config.py", line 193, in create
2023-02-15 07:51:15,782: import_module(entry)
2023-02-15 07:51:15,783:
I did « pip install Django-webpush » (no mistake), I executed « python manage.py migrate » (in line with instructions on host as well, no mistake at this point, migration is done successfully).
I have the Error when I try to reload the application on host.
Anyone can help?
Related
I am trying to host my local web app on pythonanywhere. [Beginner to Django and web-development]
I am facing the following error while launching the app:
Error running WSGI application
2021-04-26 21:46:32,020: ModuleNotFoundError: No module named 'myapp'
2021-04-26 21:46:32,020: File "/var/www/username_pythonanywhere_com_wsgi.py", line 16, in <module>
2021-04-26 21:46:32,020: application = get_wsgi_application()
2021-04-26 21:46:32,020:
2021-04-26 21:46:32,020: File "/home/username/.virtualenvs/web-virtualenv/lib/python3.8/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2021-04-26 21:46:32,020: django.setup(set_prefix=False)
2021-04-26 21:46:32,020:
2021-04-26 21:46:32,020: File "/home/username/.virtualenvs/web-virtualenv/lib/python3.8/site-packages/django/__init__.py", line 19, in setup
2021-04-26 21:46:32,021: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2021-04-26 21:46:32,021:
2021-04-26 21:46:32,021: File "/home/username/.virtualenvs/web-virtualenv/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__
2021-04-26 21:46:32,021: self._setup(name)
2021-04-26 21:46:32,021:
2021-04-26 21:46:32,021: File "/home/username/.virtualenvs/web-virtualenv/lib/python3.8/site-packages/django/conf/__init__.py", line 69, in _setup
2021-04-26 21:46:32,021: self._wrapped = Settings(settings_module)
2021-04-26 21:46:32,021:
2021-04-26 21:46:32,021: File "/home/username/.virtualenvs/web-virtualenv/lib/python3.8/site-packages/django/conf/__init__.py", line 170, in __init__
2021-04-26 21:46:32,021: mod = importlib.import_module(self.SETTINGS_MODULE)
File locations:
The settings.py file is located at:
/home/username/WebDev/Website/Django/MyApp/myapp/myapp
I have modified '/var/www/username_pythonanywhere_com_wsgi.py' file as:
"""
WSGI config for myapp project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os
import sys
sys.path.append("/home/username/WebDev/Website/Django/MyApp/myapp")
os.environ('DJANGO_SETTINGS_MODULE', 'myapp.settings')
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I have looked at the similar question on stackoverflow but still cant figure out what is wrong at my end.
Any pointers/help would be appreciated.
From taking a look it looks like the folder structure is fine.
What you might need to do is add the module into your INSTALLED_APPS in settings.
Or, if you're getting an import error or a module not found error for something that you believe is installed, then you've probably installed it into a version of Python or virtualenv that your code is not running in. If it's part of your code that is not being found, then your Python path is not set up so that it sees the module you're trying to import. See https://help.pythonanywhere.com/pages/DebuggingImportError/
The error is resolved.
The problem was that environ is not a function but a process parameter and hence, using it like below was the cause of the error.
os.environ('DJANGO_SETTINGS_MODULE', 'myapp.settings')
I changed the code to:
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
and the error was solved.
I'm deploying Django in Google App Engine.
I get 502 Bad Gateway and in the log I get the following error:
2021-03-08 12:08:18 default[20210308t130512] Traceback (most recent call last): File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/workers/gthread.py", line 92, in init_process super().init_process() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/workers/base.py", line 119, in init_process self.load_wsgi() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi self.wsgi = self.app.wsgi() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 49, in load return self.load_wsgiapp() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp return util.import_app(self.app_uri) File "/layers/google.python.pip/pip/lib/python3.9/site-packages/gunicorn/util.py", line 358, in import_app mod = importlib.import_module(module) File "/opt/python3.9/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/srv/main.py", line 1, in from django_project.wsgi import application File "/srv/django_project/wsgi.py", line 16, in application = get_wsgi_application() File "/layers/google.python.pip/pip/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application django.setup(set_prefix=False) File "/layers/google.python.pip/pip/lib/python3.9/site-packages/django/init.py", line 19, in setup configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) File "/layers/google.python.pip/pip/lib/python3.9/site-packages/django/conf/init.py", line 82, in getattr self._setup(name) File "/layers/google.python.pip/pip/lib/python3.9/site-packages/django/conf/init.py", line 69, in _setup self._wrapped = Settings(settings_module) File "/layers/google.python.pip/pip/lib/python3.9/site-packages/django/conf/init.py", line 170, in init mod = importlib.import_module(self.SETTINGS_MODULE) File "/opt/python3.9/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/srv/django_project/settings.py", line 84, in import pymysql # noqa: 402 ModuleNotFoundError: No module named 'pymysql'
The problem is that I already installed pymysql, in fact if I run pip3 install pymysql, I get Requirement already satisfied: ...
Why is that?
Thanks in advance!
Edit:
Here's requirements.txt:
asgiref==3.3.1
attrs==20.3.0
Automat==20.2.0
certifi==2020.12.5
cffi==1.14.4
chardet==4.0.0
constantly==15.1.0
cryptography==3.4.1
cssselect==1.1.0
Django==3.1.6
django-phonenumber-field==5.0.0
django-widget-tweaks==1.4.8
hyperlink==21.0.0
idna==2.10
incremental==17.5.0
instaloader==4.6.1
itemadapter==0.2.0
itemloaders==1.0.4
jmespath==0.10.0
jsonfield==3.1.0
lxml==4.6.2
parsel==1.6.0
phonenumberslite==8.12.18
progress==1.5
Protego==0.1.16
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.20
PyDispatcher==2.0.5
PyHamcrest==2.0.2
pyOpenSSL==20.0.1
pytz==2021.1
queuelib==1.5.0
requests==2.25.1
schedule==0.6.0
Scrapy==2.4.1
semantic-version==2.8.5
service-identity==18.1.0
setuptools-rust==0.11.6
six==1.15.0
sqlparse==0.4.1
toml==0.10.2
urllib3==1.26.3
w3lib==1.22.0
zope.interface==5.2.0
If you run pip3 install pymysql in your local computer, this does not mean that when you deploy the app this module is packaged. In fact GAE attempts to install everything at build time using your requirements.txt file so it doesn't matter if you installed everything in your PC since GAE will not use what you have in local (talking about packages installed with pip).
Checking your requirements.txt file I do not see that the package PyMySQL is added. You should add it to that file and attempt to deploy again.
"pymysql" package is missing (not installed) according to the message below from your error:
ModuleNotFoundError: No module named 'pymysql'
So, you need to run this command below to install "pymysql":
pip install pymysql
I'm trying to start a flask application with gunicorn but i'm facing an issue.
When starting it from command line it works fine with this command:
/usr/local/bin/gunicorn --preload --certfile /etc/letsencrypt/live/server_name.net/fullchain.pem --keyfile /etc/letsencrypt/live/server_name.net/privkey.pem -w 17
-b 0.0.0.0:9090 wsgi:app
The same command from a .sh script raise an error :
Traceback (most recent call last):
File "/usr/local/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 61, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 221, in run
super(Application, self).run()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 70, in run
Arbiter(self).run()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/arbiter.py", line 58, in __init__
self.setup(app)
File "/usr/local/lib/python3.4/dist-packages/gunicorn/arbiter.py", line 118, in setup
self.app.wsgi()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 65, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.4/dist-packages/gunicorn/util.py", line 372, in import_app
__import__(module)
ImportError: No module named '.0'
Both cli and .sh are run as root.
The same script works fine on a different server so i guess there is a problem with the environment.
I tried to add in the script the following lines at the beginning of the script without success:
$PYTHONPATH=/path/to/my/app
and
$PWD=/path/to/my/app
This is the wsgi file i'm using:
from api import app
if __name__ == "__main__":
app.run()
Any idea what the problem could be?
I was finally able to solve this problem. The following script seems to be working:
cd /path_to_app/
gunicorn --certfile=/etc/letsencrypt/live/server_name.net/fullchain.pem --keyfile=/etc/letsencrypt/live/server_name.net/privkey.pem -w 4 -b 0.0.0.0:9090 wsgi:app
I am trying to deploy my django application on the pythonanywhere. I have install all the packages that requires for the application. I am also using django_select2 reusable app in my application.
Firstly, i activate virtual environment and install the django_select2 by this command :
$ pip install django_select2
When i execute below command
$ pip freeze
cryptography==2.2.2
Django==2.0.7
django-appconf==1.0.2
django-select2==6.1.0
Flask==1.0.2
Flask-JWT==0.3.2
Flask-SQLAlchemy==2.3.2
furl==1.2
idna==2.7
As you see django_select2 is also in the installed list. I also check site-packages inside my virual environment. There is also django_select2 folder.
However when i run my app it generates the ImportError: No module named 'django_select2' inside my error.log
Here is the part of my error.log
2018-07-14 14:18:53,934: Error running WSGI application
2018-07-14 14:18:53,934: ImportError: No module named 'django_select2'
2018-07-14 14:18:53,934: File "/var/www/harunergul_pythonanywhere_com_wsgi.py", line 22, in <module>
2018-07-14 14:18:53,935: application = get_wsgi_application()
2018-07-14 14:18:53,935:
2018-07-14 14:18:53,935: File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2018-07-14 14:18:53,935: django.setup(set_prefix=False)
2018-07-14 14:18:53,935:
2018-07-14 14:18:53,935: File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 27, in setup
2018-07-14 14:18:53,935: apps.populate(settings.INSTALLED_APPS)
2018-07-14 14:18:53,935:
2018-07-14 14:18:53,935: File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 85, in populate
2018-07-14 14:18:53,936: app_config = AppConfig.create(entry)
2018-07-14 14:18:53,936:
2018-07-14 14:18:53,936: File "/usr/local/lib/python3.5/dist-packages/django/apps/config.py", line 90, in create
2018-07-14 14:18:53,936: module = import_module(entry)
Any suggestions? What i have missing?
The problem is application is not using virtual environment in this case. If we look at the below line we will see /usr/local/... . So the application is using pythonanywhere.com default environment.
File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13,
which means whatever we install in our virtualenv has no effect on default server. In pythonanywhere.com there is virtualenv menu, be sure if you input correct path info in this menu.
The default pip on PythonAnywhere is for Python 2.7, so you've been installing your modules into the wrong version of Python (your web app is using 3.5). Use pip3.5 to install your modules.
I have installed and probably right configurated apache2, mod_wsgi and python 2.7.5. The problem is that 127.0.0.1 is not opening (loading is just freezed) and I see following log in error.log:
[Wed Jun 19 14:49:11 2013] [notice] Apache/2.2.22 (Ubuntu) mod_wsgi/3.4 Python/2.7.3 configured -- resuming normal operations
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site.py", line 548, in <module>
main()
File "/usr/local/lib/python2.7/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/lib/python2.7/site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/lib/python2.7/site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/lib/python2.7/site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/lib/python2.7/sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "/usr/local/lib/python2.7/sysconfig.py", line 449, in get_config_vars
import re
File "/usr/local/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/usr/local/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/usr/local/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/usr/local/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
Tried to restart apache, but it's not working. Thanks for any help!
Just found solution. I checked 'sys.prefix' in my python's interpretator and it printed '/usr/local', but I had not set WSGIPythonHome in apache config (as written in mod_wsgi docs for this case). And just for experiment I set 'WSGIPythonHome /usr'. It's strange, but it resolves my problem, everything is fine now!