getting issues while deploying fastapi backend in railway

dheerajk-devTRIAL

4 months ago

build is being successful but while running the container so please I need help in this. I am sharing the error:

File "/opt/venv/bin/uvicorn", line 8, in

sys.exit(main())

         ^^^^^^

File "/opt/venv/lib/python3.12/site-packages/click/core.py", line 1157, in call

return self.main(*args, **kwargs)

       ^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.12/site-packages/click/core.py", line 1078, in main

rv = self.invoke(ctx)

     ^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke

return ctx.invoke(self.callback, **ctx.params)

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.12/site-packages/click/core.py", line 783, in invoke

return __callback(*args, **kwargs)

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.12/site-packages/uvicorn/main.py", line 412, in main

run(

File "/opt/venv/lib/python3.12/site-packages/uvicorn/main.py", line 579, in run

[server.run](server.run)()

File "/opt/venv/lib/python3.12/site-packages/uvicorn/server.py", line 65, in run

return [asyncio.run](asyncio.run)(self.serve(sockets=sockets))

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

self.loaded_app = import_from_string([self.app](self.app))

File "/app/app/main.py", line 6, in

File "/root/.nix-profile/lib/python3.12/asyncio/runners.py", line 194, in run

from app.detections import routes as detection_routes

return [runner.run](runner.run)(main)

File "/app/app/detections/routes.py", line 5, in

       ^^^^^^^^^^^^^^^^

from app.detections.detection import detect_objects_from_camera

File "/app/app/detections/detection.py", line 1, in

File "/opt/venv/lib/python3.12/site-packages/uvicorn/importer.py", line 19, in importfromstring

module = importlib.import_module(module_str)

File "/root/.nix-profile/lib/python3.12/asyncio/runners.py", line 118, in run

import cv2

         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

return self._[loop.run](loop.run)_until_complete(task)

File "/opt/venv/lib/python3.12/site-packages/cv2/init.py", line 181, in

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

bootstrap()

File "/opt/venv/lib/python3.12/site-packages/cv2/init.py", line 153, in bootstrap

File "/root/.nix-profile/lib/python3.12/asyncio/baseevents.py", line 687, in rununtil_complete

native_module = importlib.import_module("cv2")

File "/root/.nix-profile/lib/python3.12/importlib/init.py", line 90, in import_module

return future.result()

return _bootstrap._gcd_import(name[level:], package, level)

                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

       ^^^^^^^^^^^^^^^

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.12/site-packages/uvicorn/server.py", line 69, in serve

await self._serve(sockets)

File "/opt/venv/lib/python3.12/site-packages/uvicorn/server.py", line 76, in _serve

config.load()

File "/root/.nix-profile/lib/python3.12/importlib/init.py", line 90, in import_module

File "/opt/venv/lib/python3.12/site-packages/uvicorn/config.py", line 434, in load

return _bootstrap._gcd_import(name[level:], package, level)

File "", line 1387, in gcdimport

File "", line 1360, in findand_load

File "", line 1331, in findandloadunlocked

File "", line 935, in loadunlocked

File "", line 995, in exec_module

File "", line 488, in callwithframesremoved

ImportError: libGL.so.1: cannot open shared object file: No such file or directory

View Deploy details

> ⓘ Deployment information is only viewable by project members and Railway employees.

Solved

14 Replies

4 months ago

Hello,

Are you using opencv?


dheerajk-devTRIAL

4 months ago

yes


4 months ago

Try replacing it with the headless version.


brody

Try replacing it with the headless version.

dheerajk-devTRIAL

4 months ago

I have already replaced with

opencv-python-headless==4.8.0.74

but not worked. same issue I am getting


4 months ago

I would have to say that another package is downloading the non headless version still.


4 months ago

Yep, if you search your logs for opencv_python the non headless version is indeed being installed.

Try setting a NIXPACKS_INSTALL_CMD service variable to -

python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt && pip uninstall -y opencv_python

brody

Yep, if you search your logs for opencv_python the non headless version is indeed being installed.Try setting a NIXPACKS_INSTALL_CMD service variable to -python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt && pip uninstall -y opencv_python

dheerajk-devTRIAL

4 months ago

where I should set this variable? in env variables?


4 months ago

As a service variable -

https://docs.railway.com/overview/the-basics#service-variables

Also, FWIW, we are the only two users in this thread, so replying to every message doesn't make a difference.


dheerajk-devTRIAL

4 months ago

okay thanks let me try this


dheerajk-devTRIAL

4 months ago

after adding, I am getting this error:
```ERROR: Exception:

Traceback (most recent call last):

File "/opt/venv/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 105, in runwrapper

status = innerrun()

^^^^^^^^^^^^

File "/opt/venv/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 96, in innerrun

return self.run(options, args)

^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.12/site-packages/pip/_internal/commands/uninstall.py", line 106, in run

uninstall_pathset = req.uninstall(

^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.12/site-packages/pip/_internal/req/req_install.py", line 723, in uninstall

uninstalled_pathset.remove(auto_confirm, verbose)

File "/opt/venv/lib/python3.12/site-packages/pip/_internal/req/req_uninstall.py", line 364, in remove

if auto_confirm or self._allowed_to_proceed(verbose):

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.12/site-packages/pip/_internal/req/req_uninstall.py", line 404, in allowedto_proceed

return ask("Proceed (Y/n)? ", ("y", "n", "")) != "n"

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/venv/lib/python3.12/site-packages/pip/_internal/utils/misc.py", line 233, in ask

response = input(message)

^^^^^^^^^^^^^^

EOFError: EOF when reading a line``


4 months ago

I've revised the command I gave above, please try it.


dheerajk-devTRIAL

4 months ago

Now I am getting this error:

Starting Container

Jan 19 12:44:16

Traceback (most recent call last):

Jan 19 12:44:16

 File "/opt/venv/bin/uvicorn", line 8, in <module>

Jan 19 12:44:16

 sys.exit(main())

Jan 19 12:44:16

 ^^^^^^

Jan 19 12:44:16

 File "/opt/venv/lib/python3.12/site-packages/click/core.py", line 1157, in call

Jan 19 12:44:16

 return self.main(*args, **kwargs)

Jan 19 12:44:16

 ^^^^^^^^^^^^^^^^^^^^^^^^^^

Jan 19 12:44:16

 File "/opt/venv/lib/python3.12/site-packages/click/core.py", line 1078, in main

Jan 19 12:44:16

 rv = self.invoke(ctx)

Jan 19 12:44:16

 ^^^^^^^^^^^^^^^^

Jan 19 12:44:16

 File "/opt/venv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke

Jan 19 12:44:16

 return ctx.invoke(self.callback, **ctx.params)

Jan 19 12:44:16

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Jan 19 12:44:16

 File "/opt/venv/lib/python3.12/site-packages/click/core.py", line 783, in invoke

Jan 19 12:44:16

 return __callback(*args, **kwargs)

Jan 19 12:44:16

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Jan 19 12:44:16

 File "/opt/venv/lib/python3.12/site-packages/uvicorn/main.py", line 412, in main

Jan 19 12:44:16

 run(

Jan 19 12:44:16

 File "/opt/venv/lib/python3.12/site-packages/uvicorn/main.py", line 579, in run

Jan 19 12:44:16

 server.run()

Jan 19 12:44:16

 File "/opt/venv/lib/python3.12/site-packages/uvicorn/server.py", line 65, in run

Jan 19 12:44:16

 return asyncio.run(self.serve(sockets=sockets))

Jan 19 12:44:16

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Jan 19 12:44:16

 File "/root/.nix-profile/lib/python3.12/asyncio/runners.py", line 194, in run

Jan 19 12:44:16

 return runner.run(main)

Jan 19 12:44:16

 ^^^^^^^^^^^^^^^^

Jan 19 12:44:16

 File "/root/.nix-profile/lib/python3.12/asyncio/runners.py", line 118, in run

Jan 19 12:44:16

 return self._loop.run_until_complete(task)

Jan 19 12:44:16

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Jan 19 12:44:16

 File "/root/.nix-profile/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete

Jan 19 12:44:16

 return future.result()

Jan 19 12:44:16

 ^^^^^^^^^^^^^^^

Jan 19 12:44:16

 File "/opt/venv/lib/python3.12/site-packages/uvicorn/server.py", line 69, in serve

Jan 19 12:44:16

 await self._serve(sockets)

Jan 19 12:44:16

 File "/opt/venv/lib/python3.12/site-packages/uvicorn/server.py", line 76, in _serve

Jan 19 12:44:16

 config.load()

Jan 19 12:44:16

 File "/opt/venv/lib/python3.12/site-packages/uvicorn/config.py", line 434, in load

Jan 19 12:44:16

 self.loaded_app = import_from_string(self.app)

Jan 19 12:44:16

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Jan 19 12:44:16

 File "/opt/venv/lib/python3.12/site-packages/uvicorn/importer.py", line 22, in import_from_string

Jan 19 12:44:16

 raise exc from None

Jan 19 12:44:16

 File "/opt/venv/lib/python3.12/site-packages/uvicorn/importer.py", line 19, in import_from_string

Jan 19 12:44:16

 module = importlib.import_module(module_str)

Jan 19 12:44:16

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Jan 19 12:44:16

 File "/root/.nix-profile/lib/python3.12/importlib/__init__.py", line 90, in import_module

Jan 19 12:44:16

 return bootstrap.gcd_import(name[level:], package, level)

Jan 19 12:44:16

 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Jan 19 12:44:16

 File "<frozen importlib._bootstrap>", line 1387, in gcdimport

Jan 19 12:44:16

 File "<frozen importlib._bootstrap>", line 1360, in findand_load

Jan 19 12:44:16

 File "<frozen importlib._bootstrap>", line 1331, in findand_load_unlocked

Jan 19 12:44:16

 File "<frozen importlib._bootstrap>", line 935, in loadunlocked

Jan 19 12:44:16

 File "<frozen importlib._bootstrap_external>", line 995, in exec_module

Jan 19 12:44:16

 File "<frozen importlib._bootstrap>", line 488, in callwith_frames_removed

Jan 19 12:44:16

 File "/app/app/main.py", line 6, in <module>

Jan 19 12:44:16

 from app.detections import routes as detection_routes

Jan 19 12:44:16

 File "/app/app/detections/routes.py", line 5, in <module>

Jan 19 12:44:16

 from app.detections.detection import detect_objects_from_camera

Jan 19 12:44:16

 File "/app/app/detections/detection.py", line 1, in <module>

Jan 19 12:44:16

 import cv2

Jan 19 12:44:16

ModuleNotFoundError: No module named 'cv2'

Jan 19 12:44:19

Traceback (most recent call last):

I think it's not installing packages from requirements.txt file


brody

I've revised the command I gave above, please try it.

dheerajk-devTRIAL

4 months ago

please help


4 months ago

Hello,

Looks like your latest deploy is active and responsive!


Status changed to Solved brody 4 months ago


getting issues while deploying fastapi backend in railway - Railway Help Station