Open chflame163 opened 8 months ago
This can also be caused by having multiple opencv packages installed simultaneously, eg opencv-python
and opencv-contrib-python
. If that happens, the only solution I've found is to uninstall anything except for opencv-contrib-python
, because it includes everything in all the other variants.
Unfortunately some custom node packs explicitly list requirements for opencv-python
or opencv-python-headless
, and when they get updated by the manager, it reinstalls "missing" dependencies, and then you have to go back and uninstall them again after it's done. I wish there was a better solution but I haven't found one yet.
Thank you for your detailed explanation. and thank you for your great work at ComfyUI Image Filters.
Later, I uninstalled opencv-contrib-python and reinstalled it, setting the version to 4.7.0.72. I did this because I couldn't uninstall opencv-python>=4.7.0.72, as it's a dependency for the comfyui_controlnet_aux node. Therefore, I had to install opencv-contrib-python==4.7.0.72.
I hope the author can fully resolve this issue instead of following the method you mentioned earlier, such as pip uninstall opencv-contrib-python followed by pip install opencv-contrib-python again. This approach simply doesn't solve the problem. While using a specific version of opencv-contrib-python to install, all plugins are now functioning normally, but seeing error messages every time I start up is anxiety-inducing. Moreover, when updating the ComfyUI_LayerStyle node in the manager, all dependencies revert to their previous state, causing ComfyUI_LayerStyle, ComfyUI_InstantID, and comfyui_controlnet_aux nodes to fail loading again. Therefore, I urge the author to thoroughly address this issue.
Wibur, the reason you're getting an error is because you have both opencv-python and opencv-contrib-python installed in the same environment, which is not something that is supported by opencv. Opencv-contrib-python will actually satisfy any requirements for opencv-python or headless variants, because it includes everything that is in all the other 3 variants. Pip doesn't understand this, it sees them as separate packages, but when you import cv2 into a python script, it does not matter that you have contrib instead.
As I understand it, if you have opencv-python and opencv-contrib-python installed at the same time, any import statements will default to importing from opencv-python, which is what causes the cv2.ximgproc
error. The fix is to uninstall opencv-python, even though it's "required" by comfyui_controlnet_aux. Opencv-contrib-python will also meet that reqirement, but pip is just not smart enough to understand. As for versions, I'm using 4.9.0.80 with no issues.
pip install opencv_python>=4.7.0.72 pip install opencv_contrib_python_headless>=4.7.0.72 pip install opencv_contrib_python>=4.7.0.72 pip install opencv_python_headless>=4.7.0.72 最好这样做,因为 comfyui_controlnet_aux 插件和其他几个插件指定版本 >= 4.7 .0.72
In this way, version inconsistency may still occur. It is safe to use ==, and several other plug-ins are compatible with higher versions. There is no need to worry. I have practiced these.
Unfortunate things happen. After I had them all == 4.9.0.80. A new problem appeared
pip uninstall opencv_python pip install opencv_python==4.9.0.80 pip install opencv_contrib_python_headless==4.9.0.80 pip install opencv_contrib_python==4.9.0.80 pip install opencv_python_headless==4.9.0.80
You only need to install the above four dependency packages at the same time and keep the versions consistent to solve the problem perfectly (it does not have to be 4.9xxxx, other versions can also be used, the important thing is to keep them consistent)
Just tested and this did work for me. Guess I'm adding all 4 to the requirements for my project, lol. No errors related to guidedfilter or gapi after updating comfy+extensions, including controlnet_aux.
requirements.txt for reference
pip uninstall opencv_python pip install opencv_python==4.9.0.80 pip install opencv_contrib_python_headless==4.9.0.80 pip install opencv_contrib_python==4.9.0.80 pip install opencv_python_headless==4.9.0.80 You only need to install the above four dependency packages at the same time and keep the versions consistent to solve the problem perfectly (it does not have to be 4.9xxxx, other versions can also be used, the important thing is to keep them consistent)
Just tested and this did work for me. Guess I'm adding all 4 to the requirements for my project, lol. No errors related to guidedfilter or gapi after updating comfy+extensions, including controlnet_aux.
requirements.txt for reference
If you have installed both comfyui-reactor-node and comfyui_controlnet_aux, then the issue must still exist. comfyui_controlnet_aux will fail to load. The solution to this problem is to first execute python.exe -m pip uninstall -y opencv-python opencv-contrib-python opencv-python-headless opencv-contrib-python-headless and then execute python.exe -m pip install opencv-python==4.7.0.72. Now comfyui_controlnet_aux and comfyui-reactor-node can run normally together. However, ComfyUI_LayerStyle is now unable to run, so the errors occurring between these three plugins leave me puzzled. Unless I give up one of the plugins, I cannot resolve this.
It's like having three musketeers. They contend with each other, incompatible like water and fire.
After I removed comfyui-reactor-node. They are now in a good place. Import time for custom nodes: 0.4 seconds: D:\AI\ComfyUIbats\ComfyUI\custom_nodes\ComfyUI-Manager 0.9 seconds D:\AI\ComfyUIbats\ComfyUI\custom_nodes\comfyui_controlnet_aux 26.3 seconds D:\AI\ComfyUIbats\ComfyUI\custom_nodes\ComfyUI_LayerStyle
Start Server
I have redeployed comfyui, currently only installing comfyui-reactor-node, ComfyUI-Manager, ComfyUI_LayerStyle, and comfyui_controlnet_aux plugins. I have aligned the version of the OpenCV library. Now with all four plugins installed and comfyui launched, comfyui_controlnet_aux and ComfyUI_LayerStyle fail to load, with an error message: "AttributeError: module 'cv2.gapi.wip.draw' has no attribute 'Text'". For details, please refer to the environment dependency snapshot and startup information I provided below. requirements.txt comfyui.bat.txt
After shutting down comfyui_controlnet_aux and restarting comfyui, ComfyUI_LayerStyle fails to load again with the error message: "AttributeError: module 'cv2.gapi.wip.draw' has no attribute 'Text'". comfyui.txt
After importing comfyui_controlnet_aux again and simultaneously closing ComfyUI_LayerStyle, then restarting comfyui, comfyui_controlnet_aux fails to load with the error message: "AttributeError: module 'cv2.gapi.wip.draw' has no attribute 'Text'". comfyui.txt
After importing ComfyUI_LayerStyle, this time I closed comfyui-reactor-node and restarted comfyui. Finally, everything is working fine now, which is quite perplexing. I really need all three plugins, but now I have to give up starting one of them in order to run smoothly. comfyui.txt
It fix for me in Python 3.10.11 after the recommended version uninstall/install method. python.exe -m pip uninstall -y opencv_python python.exe -m pip install opencv_python==4.7.0.72 opencv_contrib_python_headless==4.7.0.72 opencv_contrib_python==4.7.0.72 opencv_python_headless==4.7.0.72
pip list ... opencv-contrib-python 4.7.0.72 opencv-contrib-python-headless 4.7.0.72 opencv-python 4.7.0.72 opencv-python-headless 4.7.0.72 ...
Hi everyone. I saw the discussion. I have an idea to make the 'opencv-contrib-python' as an internal package, which should completely solve the problem. But I encountered a problem, when I doing this, many errors have occurred, and I don't know how to solve it. I find this is not a good idea.
After importing ComfyUI_LayerStyle, this time I closed comfyui-reactor-node and restarted comfyui. Finally, everything is working fine now, which is quite perplexing. I really need all three plugins, but now I have to give up starting one of them in order to run smoothly. comfyui.txt
As you said, the comfyui-reactor-node has done some processing on sys.modules. I checked his code and found the issue at line 32 of comfyui-reactor-node/ init. py.
Modifying this line to
if module not in original_modules and not module.startswith("google.protobuf") and not module.startswith("onnx") and not module.startswith("cv2"):
can solve the problem.
After importing ComfyUI_LayerStyle, this time I closed comfyui-reactor-node and restarted comfyui. Finally, everything is working fine now, which is quite perplexing. I really need all three plugins, but now I have to give up starting one of them in order to run smoothly. comfyui.txt导入ComfyUI_LayerStyle后,这次我关闭了 comfyui-reactor-node 并重新启动了 comfyui。最后,现在一切正常,这非常令人困惑。我真的需要所有三个插件,但现在我必须放弃启动其中一个才能顺利运行。comfyui.txt
As you said, the comfyui-reactor-node has done some processing on sys.modules. I checked his code and found the issue at line 32 of comfyui-reactor-node/ init. py.正如您所说,comfyui-reactor-node 对 sys.modules 进行了一些处理。我检查了他的代码,并在 comfyui-reactor-node/ init 的第 32 行发现了问题。py。
Modifying this line to将此行修改为
if module not in original_modules and not module.startswith("google.protobuf") and not module.startswith("onnx") and not module.startswith("cv2"):
can solve the problem.可以解决问题。
Thank you very much for your help, they are now working perfectly after I made the changes the way you did, but I'm still a bit worried. If the next update will the same problem occur again ComfUI.txt [Uploading Windows PowerShell.txt…]()
After importing ComfyUI_LayerStyle, this time I closed comfyui-reactor-node and restarted comfyui. Finally, everything is working fine now, which is quite perplexing. I really need all three plugins, but now I have to give up starting one of them in order to run smoothly. comfyui.txt导入ComfyUI_LayerStyle后,这次我关闭了 comfyui-reactor-node 并重新启动了 comfyui。最后,现在一切正常,这非常令人困惑。我真的需要所有三个插件,但现在我必须放弃启动其中一个才能顺利运行。comfyui.txt
As you said, the comfyui-reactor-node has done some processing on sys.modules. I checked his code and found the issue at line 32 of comfyui-reactor-node/ init. py.正如您所说,comfyui-reactor-node 对 sys.modules 进行了一些处理。我检查了他的代码,并在 comfyui-reactor-node/ init 的第 32 行发现了问题。py。 Modifying this line to将此行修改为
if module not in original_modules and not module.startswith("google.protobuf") and not module.startswith("onnx") and not module.startswith("cv2"):
can solve the problem.可以解决问题。Thank you very much for your help, they are now working perfectly after I made the changes the way you did, but I'm still a bit worried. If the next update will the same problem occur again ComfUI.txt Uploading Windows PowerShell.txt…
This require that plugin author to submit code modifications.
Fixed on the ReActor Node side https://github.com/Gourieff/comfyui-reactor-node/commit/b08d47588c0683b186dc9fd623e86bbeb5eb9dba All 3 nodes should work together correctly for now
Fixed on the ReActor Node side Gourieff/comfyui-reactor-node@b08d475 All 3 nodes should work together correctly for now
Thank you for your works.
What is the final solution? reinstall related opencv package or update all the node to latest?
- Solution:
Close ComfyUI and open the terminal window in the plugin directory and execute the following command :
../../../python_embeded/python.exe -s -m pip uninstall -y opencv-python opencv-python-headless opencv-contrib-python-headless opencv-contrib-python
then enter:
../../../python_embeded/python.exe -s -m pip install opencv-contrib-python
Restart ComfyUI.
This way.
- Solution:
Close ComfyUI and open the terminal window in the plugin directory and execute the following command :
../../../python_embeded/python.exe -s -m pip uninstall -y opencv-python opencv-python-headless opencv-contrib-python-headless opencv-contrib-python
then enter:
../../../python_embeded/python.exe -s -m pip install opencv-contrib-python
Restart ComfyUI.
This way.
I have tried, still got red node on the comfyui. Still checking. No error on starting, but still red node
I have tried, still got red node on the comfyui. Still checking. No error on starting, but still red node !
Please attach the log of ComfyUI starting, and run ../../../python_embeded/python.exe -s -m pip list
terminal command from plugin folder,list all of the startwith "opencv...." package here.
Log file: comfyui_8188.log Result of pip list
open-clip-torch 2.24.0
openai 0.28.1
opencv-contrib-python 4.9.0.80
opendatalab 0.0.9
openmim 0.3.9
Error in my comfyui
Thanks for your help.
Log file: comfyui_8188.log Result of pip list
open-clip-torch 2.24.0 openai 0.28.1 opencv-contrib-python 4.9.0.80 opendatalab 0.0.9 openmim 0.3.9
Error in my comfyui Thanks for your help.
There is no "ImportError:" in your log file, and the LayerStyle also shows that it has been loaded normally. You have installed opencv-contrib-python and only have this one opencv package, indicating that you are not THIS ISSUE. I saw you have installed 100 plugins. There may be a possibility of conflicts with so many plugins. I suggest you deploy a new ComfyUI environment for testing in another directory.
Error in my comfyui Thanks for your help.
There is no "ImportError:" in your log file, and the LayerStyle also shows that it has been loaded normally. You have installed opencv-contrib-python and only have this one opencv package, indicating that you are not THIS ISSUE. I saw you have installed 100 plugins. There may be a possibility of conflicts with so many plugins. I suggest you deploy a new ComfyUI environment for testing in another directory.
Thanks a lot. I will try it. Another question, is there any easy way to find the confilct nodes?
Thanks a lot. I will try it. Another question, is there any easy way to find the confilct nodes?
This is a tedious task that requires some time to verify.
Firstly, update your ComfyUI and all plugins to latest version. If this still persists, you can troubleshoot the issue by moving the plugin folders in custom_modes folder.
I saw that you installed ComfyUI on the E drive, so
temp_dir
custom_dodes
except LayerStyle
to temp_dir, and then start ComfyUI to test if there are any issues with LayerStyle.temp_dir/ConfyUI_Manager
folder to custom_nodes
, then start ComfyUI and test. If proves that these two plugins are not problematic, then: temp_dir
to custom_nodes
, then launch ComfyUI to test for any conflicts caused by these plugins. custom_modes
to this folder. Then test if there are any issues with the reserved half. Your kind reply is most appreciated. I will try it.
@spacepxl @wibur0620 @chflame163 The solution to this problem is as follows:
pip uninstall opencv_python pip install opencv_python==4.9.0.80 pip install opencv_contrib_python_headless==4.9.0.80 pip install opencv_contrib_python==4.9.0.80 pip install opencv_python_headless==4.9.0.80
You only need to install the above four dependency packages at the same time and keep the versions consistent to solve the problem perfectly (it does not have to be 4.9xxxx, other versions can also be used, the important thing is to keep them consistent)
I fixed it according to your suggestion.Thanks.
still facing that problem , tried different version, uninstall, reinstall, no change ,still are unable to import guidedfilter update: was able to solve it , uninstalling one by one: opencv-contrib-python opencv-contrib-python-headless opencv-python opencv-python-headless Then reinstalling only opencv-contrib-python
This error is caused by incorrect version of the
opencv-contrib-python
package,or this package is overwriteen by other opencv packages.Solution:
- Close ComfyUI and open the terminal window in the plugin directory and execute the following command :
../../../python_embeded/python.exe -s -m pip uninstall -y opencv-python opencv-python-headless opencv-contrib-python-headless opencv-contrib-python
- To avoid other plugins install opencv packages, you can install here first, also can skip this step:
../../../python_embeded/python.exe -s -m pip install opencv-python opencv-python-headless opencv-contrib-python-headless
- Then install
opencv-contrib-python
, ensuring that it is the LAST ONE to be installed:../../../python_embeded/python.exe -s -m pip install opencv-contrib-python
- Restart ComfyUI.
where is the "plugin directory" . i have a lot plugin directory
where is the "plugin directory" . i have a lot plugin directory
ComfyUI/custom_nodes/ComfyUI_LayerStyle
where is the "plugin directory" . i have a lot plugin directory
ComfyUI/custom_nodes/ComfyUI_LayerStyle
THANK YOU!!!
Can someone drive me to a solution , as i'm facing that error message again on Fedora Linux ?
still facing that problem , tried different version, uninstall, reinstall, no change ,still are unable to import guidedfilter update: was able to solve it , uninstalling one by one: opencv-contrib-python opencv-contrib-python-headless opencv-python opencv-python-headless Then reinstalling only opencv-contrib-python
Did you do this inside ComfyUI/custom_nodes/ComfyUI_LayerStyle ?
After importing ComfyUI_LayerStyle, this time I closed comfyui-reactor-node and restarted comfyui. Finally, everything is working fine now, which is quite perplexing. I really need all three plugins, but now I have to give up starting one of them in order to run smoothly. comfyui.txt
As you said, the comfyui-reactor-node has done some processing on sys.modules. I checked his code and found the issue at line 32 of comfyui-reactor-node/ init. py.
Modifying this line to
if module not in original_modules and not module.startswith("google.protobuf") and not module.startswith("onnx") and not module.startswith("cv2"):
can solve the problem.
I tried this node set up but cant replicate the result (which looks amazing by the way). I dont have any errors.
python.exe -s -m pip install opencv-python opencv-python-headless opencv-contrib-python-headless
when i try to install the headless 2nd command, i get permissions error:
E:\comfy_ui\ComfyUI_windows_portable\python_embeded>python.exe -s -m pip install opencv-python opencv-python-headless opencv-contrib-python-headless
Requirement already satisfied: opencv-python in e:\comfy_ui\comfyui_windows_portable\python_embeded\lib\site-packages (4.10.0.84)
Requirement already satisfied: opencv-python-headless in e:\comfy_ui\comfyui_windows_portable\python_embeded\lib\site-packages (4.10.0.84)
Collecting opencv-contrib-python-headless
Using cached opencv_contrib_python_headless-4.10.0.84-cp37-abi3-win_amd64.whl.metadata (20 kB)
Requirement already satisfied: numpy>=1.21.2 in e:\comfy_ui\comfyui_windows_portable\python_embeded\lib\site-packages (from opencv-python) (1.26.4)
Using cached opencv_contrib_python_headless-4.10.0.84-cp37-abi3-win_amd64.whl (45.4 MB)
Installing collected packages: opencv-contrib-python-headless
ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied: 'E:\comfy_ui\ComfyUI_windows_portable\python_embeded\Lib\site-packages\cv2\cv2.pyd'
Consider using the --user
option or check the permissions.
when i try to install the headless 2nd command, i get permissions error:
Perhaps ComfyUi has not been closed?
Thanks small oversightStill getting later style errors when I start comfyui though. Opened an issue Best, Raf On 19 Jun 2024, at 04:17, chflame163 @.***> wrote:
when i try to install the headless 2nd command, i get permissions error:
Perhaps ComfyUi has not been closed?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>
none of the above fixed. Havent tried re-installing with opencv-python>=4.7.0.72 Is that still the best solution? i tried using the repair_dependency.bat also but no luck
i have installed layer style on a fresh comfy install, following all the suggestions above and still get errors (repair_dependency.bat, reinstalling opencv, etc). Really looking forward to a real fix
https://github.com/chflame163/ComfyUI_LayerStyle/issues/141
Hey guys! i have managed to solve this issue: Cannot import name 'guidedFilter' from 'cv2.ximgproc'
Install: python.exe -m pip install opencv-contrib-python-headless
And open cmd prompt and install this:
I am also on my discord channel to discuss bugs and issues as I am a starting python/comfyui engineer, feel free to drop by https://discord.gg/Z44Zjpurjp and say hi
More than happy to chat.
pip install --force-reinstall numpy==1.26.4 opencv-python-headless==4.10.0.84 opencv-contrib-python==4.10.0.84
python.exe -m pip install opencv_python==4.7.0.72 opencv_contrib_python_headless==4.7.0.72 opencv_contrib_python==4.7.0.72 opencv_python_headless==4.7.0.72
This version works for me.. Thx
There's a good solution for that. First of all, the reason for my error is because of the conflict between LayerStyle and controlnet_aux, so I checked the requirements file of controlnet_aux, and the opencv-python is set to >=4.7.0.72, then I looked at the LayerStyle's opencv- contrib-python does not specify a version, then set both versions to controlnet_aux to prevail 4.7.0.72, after restarting the installation environment can run normally, in order to keep my smooth use of comfui, after completing the above steps I will set to '>=' to keep my comfui running smoothly. ' to maintain a good tolerance, of course you have to remember how to deal with this situation next time!
检查opencv-python版本然后把opencv-contrib-python卸载后装一样版本,我就是这么解决的,目前没有发生什么问题。
检查opencv-python版本然后把opencv-contrib-python卸载后装一样版本,我就是这么解决的,目前没有发生什么问题。
Thank you bro. solved my problem. it works greatly!
when i run :python.exe -s -m pip install opencv-contrib-python this happening: ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. mediapipe 0.10.14 requires protobuf<5,>=4.25.3, but you have protobuf 3.20.3 which is incompatible.
when i run :python.exe -s -m pip install opencv-contrib-python this happening: ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. mediapipe 0.10.14 requires protobuf<5,>=4.25.3, but you have protobuf 3.20.3 which is incompatible.
If it works properly, ignore it
This error is caused by incorrect version of the
opencv-contrib-python
package,or this package is overwriteen by other opencv packages.Solution:
Close ComfyUI and open the terminal window in the plugin directory and execute the following command :
To avoid other plugins install opencv packages, you can install here first, also can skip this step:
Then install
opencv-contrib-python
, ensuring that it is the LAST ONE to be installed:Restart ComfyUI.