Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import error when using uwsgi with django (Symbol not found: __PyInt_AsInt)

I've tried looking for a fix, but wasn't able to. Sorry if this question exists elsewhere.

I'm following http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html, and am currently trying to make sure django works with uWSGI. I'm trying to run uWSGI --http-socket :8000 --module mysite.wsgi, but am getting:

Traceback (most recent call last):
  File "./mysite/wsgi.py", line 13, in <module>
    from django.core.wsgi import get_wsgi_application
  File "/anaconda/lib/python2.7/site-packages/django/core/wsgi.py", line 2, in <module>
    from django.core.handlers.wsgi import WSGIHandler
  File "/anaconda/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 3, in <module>
    import cgi
  File "/anaconda/lib/python2.7/cgi.py", line 50, in <module>
    import mimetools
  File "/anaconda/lib/python2.7/mimetools.py", line 6, in <module>
    import tempfile
  File "/anaconda/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/anaconda/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/anaconda/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyInt_AsInt
  Referenced from: /anaconda/lib/python2.7/lib-dynload/_io.so
  Expected in: dynamic lookup

I already had issues with uWSGI not using the right installation.uwsgi would try to use /usr/local/bin/uwsgi despite

which uwsgi
//anaconda/bin/uwsgi

, resulting in No such file or directory. Currently, I set uWSGI="//anaconda/bin/uwsgi" to get around the problem at and get uwsgi to work, but I suspect a similar problem may be occurring. I think it might be trying to use /usr/bin/python instead of /anaconda/bin/python, and it can't import from anaconda, resulting in the error. However, I'm not sure how to fix it/confirm that this is the problem, and any advice would be appreciated.

Thanks!

EDIT: I have also tried import _io using all of the current versions of python installed, and there was no problem. brew unlink python helped deal with the conflicting anaconda version for the uwsgi problem (initially fixed with alias, as above), but this issue still exists.

EDIT: Removing anaconda from $PATH, and then reinstalling/unlinking/linking django, openssl, and libxml2 "works". I'll find out if this causes problems in the later steps shortly, but I still have no idea what was happening with the anaconda install. I'd really like to figure out what's going on since I use scipy/numpy/etc. very frequently, so this is definitely a temporary fix. Any ideas?

like image 869
user124900 Avatar asked Oct 31 '22 11:10

user124900


1 Answers

I just encountered this issue trying to run uwsgi on my mac with my django project

uwsgi --http :9090 --module uwsgi_django_project.wsgi

(in this case my django project was named uwsgi_django_project)

The stack-trace from uwsgi was

Traceback (most recent call last):
  File "./uwsgi_django_project/wsgi.py", line 12, in <module>
    from django.core.wsgi import get_wsgi_application
  File "/opt/anaconda3/envs/django_uwsgi_39/lib/python3.8/site-packages/django/__init__.py", line 1, in <module>
    from django.utils.version import get_version
  File "/opt/anaconda3/envs/django_uwsgi_39/lib/python3.8/site-packages/django/utils/version.py", line 1, in <module>
    import datetime
  File "/opt/anaconda3/envs/django_uwsgi_39/lib/python3.8/datetime.py", line 8, in <module>
    import math as _math
ImportError: dlopen(/opt/anaconda3/envs/django_uwsgi_39/lib/python3.8/lib-dynload/math.cpython-38-darwin.so, 2): Symbol not found: _PyExc_MemoryError
  Referenced from: /opt/anaconda3/envs/django_uwsgi_39/lib/python3.8/lib-dynload/math.cpython-38-darwin.so
  Expected in: flat namespace
 in /opt/anaconda3/envs/django_uwsgi_39/lib/python3.8/lib-dynload/math.cpython-38-darwin.so
unable to load app 0 (mountpoint='') (callable not found or import error)

Very similar to the error OP was getting except Symbol not found: _PyExc_MemoryError instead.

I had installed uwsgi via pip inside my conda environment and apparently there is an incompatability between the package installed via pip and the anaconda environment's python.

The solution was to remove uwsgi from my environment

pip uninstall uwsgi

and install it using anaconda

conda install -c conda-forge uwsgi

after doing this and running uwsgi with my django app it worked fine.

Credit to this blog where I found the solution to my issue which probably would solve a lot of similar issues with uwsgi and django

like image 87
Danoram Avatar answered Nov 09 '22 10:11

Danoram