FastAPI working locally but not in railway

I have a fast api that uses opencv-python-headless and its giving me this error
import cv2
File "/opt/venv/lib/python3.8/site-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/opt/venv/lib/python3.8/site-packages/cv2/__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "/root/.nix-profile/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
import cv2
File "/opt/venv/lib/python3.8/site-packages/cv2/__init__.py", line 181, in <module>
bootstrap()
File "/opt/venv/lib/python3.8/site-packages/cv2/__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "/root/.nix-profile/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
Note: This project was already running before but after pushing another update in my Github Repository the deployment is crashing
45 Replies
Percy
Percy2y ago
Project ID: d942101e-d604-463a-ae38-70e444e7cef0
JJFire
JJFireOP2y ago
d942101e-d604-463a-ae38-70e444e7cef0
Brody
Brody2y ago
use the headless version of open cv
JJFire
JJFireOP2y ago
I am already using the headless version of opencv
Brody
Brody2y ago
send requirements.txt please
luna
luna2y ago
https://stackoverflow.com/a/69125651
Try installing opencv-python-headless python dependency instead of opencv-python. That includes a precompiled binary wheel with no external dependencies (other than numpy), and is intended for headless environments like Docker. This saved almost 700mb in my docker image compared with using the python3-opencv Debian package (with all its dependencies).
JJFire
JJFireOP2y ago
here is my requirements.txt
Brody
Brody2y ago
are you actually using all those packages
JJFire
JJFireOP2y ago
yes I am using those packages I have no problem with it before, but after updating pt files, and pushing changes the deployment is crashing
Brody
Brody2y ago
one of those packages might be installing the non headless version of open cv
JJFire
JJFireOP2y ago
ohh I didnt thought of that, let me check all the packages
Brody
Brody2y ago
this isn't the first time I've seen this question asked, and it's always been solved by using the headless versions
JJFire
JJFireOP2y ago
I think I have seen those questions, I have experienced it before and solved it by adding opencv-python-headless on the requirements.txt, I am now clueless on why it came back after a long time
Brody
Brody2y ago
keep looking!
JJFire
JJFireOP2y ago
I will thank you For some reason this is showing up in the Build Logs
#10 63.22 Collecting opencv-python>=4.6.0

#10 63.54 Using cached opencv_python-4.7.0.72-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (61.8 MB)
#10 63.22 Collecting opencv-python>=4.6.0

#10 63.54 Using cached opencv_python-4.7.0.72-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (61.8 MB)
its installing the non headless opencv also
Brody
Brody2y ago
dig deeper
JJFire
JJFireOP2y ago
ultralytics is the one causing it to install the non headless version but Deployment Logs says that its a missing module what should I do
luna
luna2y ago
GitHub
Can opencv-python be switched to headless? · Issue #2179 · ultralyt...
Search before asking I have searched the YOLOv8 issues and discussions and found no similar questions. Question Hi, I have ultralytics as a dependancy, however during installation it auto installs ...
JJFire
JJFireOP2y ago
it shows in the build logs this
#10 [stage-0 6/8] RUN --mount=type=cache,id=s/b1b825c1-f4eb-4696-95cb-640219e04672-/root/cache/pip,target=/root/.cache/pip python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt
#10 [stage-0 6/8] RUN --mount=type=cache,id=s/b1b825c1-f4eb-4696-95cb-640219e04672-/root/cache/pip,target=/root/.cache/pip python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt
where can I edit this? or is this built in
LaCrak27
LaCrak272y ago
as i said in the other thread, maybe the requirements.txt file can be edited to exclude that one dependency?
JJFire
JJFireOP2y ago
you can only indicate what to exclude on pip installations
luna
luna2y ago
GitHub
Can opencv-python be switched to headless? · Issue #2179 · ultralyt...
Search before asking I have searched the YOLOv8 issues and discussions and found no similar questions. Question Hi, I have ultralytics as a dependancy, however during installation it auto installs ...
JJFire
JJFireOP2y ago
thats based on what I saw online
luna
luna2y ago
An option to solve this would be switching from the requirements.txt to setuptools, which allows you to provide groups of optional dependencies, so users would be able to install only what the need, for example ultralytics, ultralytics[dev] or ultralytics[dev,extras].
oh that's for the lib not for you. 😦
As a potential workaround, you can try manually specifying each package and version in your requirements.txt file, without including any dependencies that you do not want. This will require some extra work on your end, but it should allow you to have greater control over which packages are installed. Alternatively, you can try installing Ultralytics YOLOv8 with the --no-deps flag in a separate step after installing all the other packages in your requirements.txt file. This should prevent OpenCV from being installed automatically. I hope this helps! Please let me know if you have any further questions or concerns.
JJFire
JJFireOP2y ago
thats what I am currently look it to edit the script during building/deployment
LaCrak27
LaCrak272y ago
pip install $(grep -ivE "pkg1|pkg2|pkg3" requirements.txt)
maybe put that into the custom build command in the settings with pkg1, 2, and 3 being the packages you wanna exclude
LaCrak27
LaCrak272y ago
Stack Overflow
Pip install to custom target directory and exclude specific depende...
I'm looking for a method to use pip or similiar to install a list of python packages to a custom target directory (ex./mypath/python/pkgs/ ), but also exclude/blacklist specific dependencies.
I ...
JJFire
JJFireOP2y ago
the build command is located in railway.json correct?
JJFire
JJFireOP2y ago
I have tried using it here but its not running the script
LaCrak27
LaCrak272y ago
i use it from the website itself in settings
LaCrak27
LaCrak272y ago
LaCrak27
LaCrak272y ago
(excuse the win7 and lowres, my laptop broke lmao)
JJFire
JJFireOP2y ago
I dont see where I should put the script in the settings in the build command?
LaCrak27
LaCrak272y ago
yeah, i think so
JJFire
JJFireOP2y ago
let me try that
LaCrak27
LaCrak272y ago
in the stackoverflow question someone mentions that if that doesnt work you should try this:
pip freeze | grep -vFxf pip_ignore.txt > requirements.txt
You need to put the ignored packages in pip_ignore.txt
JJFire
JJFireOP2y ago
thank you for your help, I'll try those solutions and will get baack to you after
LaCrak27
LaCrak272y ago
hope they work
JJFire
JJFireOP2y ago
I would like to thank you for everyone who helped me. Its now working. Thank you so much
Brody
Brody2y ago
awesome!
LaCrak27
LaCrak272y ago
Let's go, was it the thing i told you?
JJFire
JJFireOP2y ago
Yes I placed the pip install on the build command, remove open cv and install the headless version It can cause problems when both were installed at the same time so the headless version must be installed after deleting the non headless version
LaCrak27
LaCrak272y ago
nice! glad to know it works
Drich
Drich12mo ago
how did you do this? i'm having the same problem but it does not work on me
Want results from more Discord servers?
Add your server