saghul / pycares

Python interface for c-ares
https://pypi.org/project/pycares/
MIT License
163 stars 74 forks source link

No module named 'pycares._cares' #127

Closed mdhaynes closed 4 years ago

mdhaynes commented 4 years ago

Running from a venv on unbuntu and flask, I have imported pycares alongside python 3.7 Previously 3.6.9 it worked fine. Now I am getting an error:

File "/var/www/ctea/app/venv/lib/python3.7/site-packages/pydnsbl/checker.py", line 17, in import aiodns File "/var/www/ctea/app/venv/lib/python3.7/site-packages/aiodns/init.py", line 4, in import pycares File "/var/www/ctea/app/venv/lib/python3.7/site-packages/pycares/init.py", line 2, in from ._cares import ffi as _ffi, lib as _lib ModuleNotFoundError: No module named 'pycares._cares'

If I run python within the venv I can import pycares fine. The issue is when importing pycares from wsgi. I am not the only one with this issue:

https://github.com/constverum/ProxyBroker/issues/124 https://github.com/constverum/ProxyBroker/issues/157

Thanks in advance!

boytm commented 4 years ago

I suggest you to install pycares from source. You can run the following command:

pip uninstall pycares                                               # uninstall 
pip install -v pycares --no-binary pycares              # install from source
CUIAk37c26Ok7 commented 4 years ago

Installing pycares from the source did not solve the issue...at least not for me.

boytm commented 4 years ago

What's your full build log? I think it's like https://github.com/saghul/pycares/issues/78 . The default c-ares configure lack some functions and then cffi build failed.

mdhaynes commented 4 years ago

Running from a venv on unbuntu and flask, I have imported pycares alongside python 3.7 Previously 3.6.9 it worked fine. Now I am getting an error:

File "/var/www/ctea/app/venv/lib/python3.7/site-packages/pydnsbl/checker.py", line 17, in import aiodns File "/var/www/ctea/app/venv/lib/python3.7/site-packages/aiodns/init.py", line 4, in import pycares File "/var/www/ctea/app/venv/lib/python3.7/site-packages/pycares/init.py", line 2, in from ._cares import ffi as _ffi, lib as _lib ModuleNotFoundError: No module named 'pycares._cares'

If I run python within the venv I can import pycares fine. The issue is when importing pycares from wsgi. I am not the only one with this issue:

constverum/ProxyBroker#124 constverum/ProxyBroker#157

Thanks in advance!

In the end I discovered this was due to wsgi not detecting the correct venv. Once I fixed this, the libraries worked fine.

lok-esh commented 4 years ago

Please help me to solve this... How did you fixed it please tell in detail... I tried all possible ways nothing worked...

Dizzzmas commented 3 years ago

Having this issue right now with my Flask app on AWS Lambda.

@mdhaynes Could you please elaborate on how you've solved it?

sedrakpc commented 2 years ago

Having this issue right now with my Flask app on AWS Lambda.

@mdhaynes Could you please elaborate on how you've solved it?

Just in case anyone else still has this issues I did managed to resolve it. It seems pycares depends on native .so c/c++ library . You have to include the version for lambda environment. I managed to do this creating lambda layer with all the dependencies for my lambda function. Here is the link to the simple solution I did created for pycares, to build it you only need docker and its only 2 lines of script. Also you can find pre-build layer for python 3.8 in case it's what you needed(let me know if you need any other version).