0

Tried to deploy my railway app via django. But it wont post and crashes instead. No idea why my railway app keeps crashing. Only error I see is for TK, which i verified is installed. What is the problem? Here is the log:

File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/app/api_tutorial/wsgi.py", line 16, in <module>
application = get_wsgi_application()
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/opt/venv/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/opt/venv/lib/python3.11/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/opt/venv/lib/python3.11/site-packages/django/apps/config.py", line 269, in import_models
self.models_module = import_module(models_module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.nix-profile/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/app/drinks_app/models.py", line 1, in <module>
from turtle import width
File "/root/.nix-profile/lib/python3.11/turtle.py", line 107, in <module>
import tkinter as TK
File "/root/.nix-profile/lib/python3.11/tkinter/__init__.py", line 38, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '_tkinter'
[2023-04-21 06:44:11 +0000] [9] [INFO] Worker exiting (pid: 9)
[2023-04-21 06:44:11 +0000] [1] [INFO] Shutting down: Master
[2023-04-21 06:44:11 +0000] [1] [INFO] Reason: Worker failed to boot.
[2023-04-21 06:44:15 +0000] [1] [INFO] Starting gunicorn 20.1.0
[2023-04-21 06:44:15 +0000] [1] [INFO] Listening at: http://0.0.0.0:5663 (1)
[2023-04-21 06:44:15 +0000] [1] [INFO] Using worker: sync
[2023-04-21 06:44:15 +0000] [9] [INFO] Booting worker with pid: 9
[2023-04-21 06:44:15 +0000] [9] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/opt/venv/lib/python3.11/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/opt/venv/lib/python3.11/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/opt/venv/lib/python3.11/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.nix-profile/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/app/api_tutorial/wsgi.py", line 16, in <module>
application = get_wsgi_application()
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/venv/lib/python3.11/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/opt/venv/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/opt/venv/lib/python3.11/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/opt/venv/lib/python3.11/site-packages/django/apps/config.py", line 269, in import_models
self.models_module = import_module(models_module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.nix-profile/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Tried redownloading TK which did not help.. Reinstalled python which did not help.

  • the environment you are trying to run this app in, has no module named '_tkinter' – Umair Ayub Apr 21 '23 at 07:01
  • For other systems see here: https://stackoverflow.com/questions/25905540/importerror-no-module-named-tkinter – STerliakov Apr 21 '23 at 09:28
  • In your own words, why do you think it should be possible to use turtle graphics from within a Django railway app? How exactly do you intend for the graphics to be drawn? Should they appear in the web page contents somehow? – Karl Knechtel Apr 28 '23 at 21:24

1 Answers1

0

I hope you used a virtual environment.

Freeze you requirements with pip freeze > requirements.txt

The server on which you want to deploy your app needs to know which requirement are needed, those will be installed when deploying.

GCMeccariello
  • 339
  • 2
  • 13
  • I did both those things. The server will initially say all is good and that the app is ready. Then it will crash two minutes later. – texinterport Apr 21 '23 at 14:21
  • maybe i am missing something? here is the requirements.txt: asgiref==3.6.0 certifi==2022.12.7 charset-normalizer==3.1.0 crispy-bootstrap4==2022.1 crispy-bootstrap5==0.7 defusedxml==0.7.1 diff-match-patch==20200713 Django==4.2 django-cors-headers==3.14.0 django-crispy-forms==2.0 django-filter==23.1 django-import-export==3.2.0 djangorestframework==3.14.0 engineering-notation==0.8.0 et-xmlfile==1.1.0 gunicorn==20.1.0 idna==3.4 MarkupPy==1.14 numpy==1.24.2 oauthlib==3.2.2 odfpy==1.4.1 openpyxl==3.1.2 packaging==23.1 pandas==2.0.0 Pillow==9.5.0 plotly==5.14.1 – texinterport Apr 21 '23 at 14:22
  • python-dateutil==2.8.2 pytz==2023.3 PyYAML==6.0 requests==2.28.2 requests-oauthlib==1.3.1 six==1.16.0 sqlparse==0.4.4 tablib==3.4.0 tenacity==8.2.2 tk==0.1.0 tk-tools==0.16.0 tweepy==4.13.0 tzdata==2023.3 urllib3==1.26.15 whitenoise==6.4.0 xlrd==2.0.1 xlwt==1.3.0 – texinterport Apr 21 '23 at 14:23
  • What does it mean it crushes? Have you been able to open the website or does it crush while deploying it? I have the feeling it is related to Tkinter, look at his https://stackoverflow.com/q/5459444/16175571 – GCMeccariello Apr 21 '23 at 14:59
  • railway says it is good to go but when i click on the link I get a server error. And then the link turns red and says it crashed. Never get a chance to see the application – texinterport Apr 22 '23 at 01:26
  • That usually happens if the libraries are not installed, or the settings for connecting to the DB are wrong. It is really hard to say what the problem is. I would suggest to set `Debug=True`, deploy it again and check the error message you get from Django. – GCMeccariello Apr 22 '23 at 07:30