Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named 'pycares._cares' #127

Closed
mdhaynes opened this issue May 19, 2020 · 7 comments
Closed

No module named 'pycares._cares' #127

mdhaynes opened this issue May 19, 2020 · 7 comments

Comments

@mdhaynes
Copy link

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!

@boytm
Copy link
Contributor

boytm commented May 20, 2020

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
Copy link

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

@boytm
Copy link
Contributor

boytm commented Jun 2, 2020

What's your full build log? I think it's like #78 . The default c-ares configure lack some functions and then cffi build failed.

@mdhaynes
Copy link
Author

mdhaynes commented Jun 9, 2020

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.

@mdhaynes mdhaynes closed this as completed Jun 9, 2020
@lok-esh
Copy link

lok-esh commented Jul 5, 2020

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

@Dizzzmas
Copy link

Dizzzmas commented Nov 2, 2020

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

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

@sedrakpc
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants