py31compat error while trying to run gunicorn on PyCharm (python 2.7)

Hi,

I know python2.7 is officially unsupported now, but I'm still having to work on 2.7 projects.

I'm trying to run an app using gunicorn. From my virtualenv directly in the console (out of PyCharm)

`gunicorn --reload --paste /home/jean/dev/ckan/docker-ckan/ckan/root/etc/ckan/development.ini`, it runs just fine.

But when I try to run it inside PyCharm in debug mode, I get

```

/home/jean/dev/ckan/docker-ckan/.venv2.7/bin/python2.7 /home/jean/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/193.6494.30/plugins/python/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 43293 --file /home/jean/dev/ckan/docker-ckan/.venv2.7/bin/gunicorn --timeout 120 --paste /home/jean/dev/ckan/docker-ckan/ckan/root/etc/ckan/development.ini
Connected to pydev debugger (build 193.6494.30)
pydev debugger: process 4886 is connecting

Traceback (most recent call last):
File "/home/jean/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/193.6494.30/plugins/python/helpers/pydev/pydevd.py", line 1434, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/jean/dev/ckan/docker-ckan/.venv2.7/bin/gunicorn", line 5, in <module>
from gunicorn.app.wsgiapp import run
File "/home/jean/dev/ckan/docker-ckan/.venv2.7/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 9, in <module>
from gunicorn.app.base import Application
File "/home/jean/dev/ckan/docker-ckan/.venv2.7/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 12, in <module>
from gunicorn import util
File "/home/jean/dev/ckan/docker-ckan/.venv2.7/local/lib/python2.7/site-packages/gunicorn/util.py", line 12, in <module>
import pkg_resources
File "/home/jean/dev/ckan/docker-ckan/.venv2.7/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 70, in <module>
from . import py31compat
ImportError: cannot import name py31compat

```

Any idea what's happening ?

 

My config:

  • OS Debian 10
  • Python 2.7 in virtualenv created using virtualenv
  • PyCharm 2019.3.3 Professional Edition

Thanks in advance

4 comments
Comment actions Permalink

One of the common reason for this error is circular dependency import. Does it run without debugger from PyCharm?

 

0
Comment actions Permalink

Is it possible to provide the code sample or construct a minimal example that reproduces the issue?

0
Comment actions Permalink

Hi Andrey,

I was afraid you'd ask me that... Alas, it's a setup I'm not at liberty to divulge.

I'll try to get some time and build a minimal config where you could reproduce this.

What's weird it that I have an old virtualenv with which it's running fine. But if I build a new one from scratch, here comes the bug. I've just changed my computer, and was trying with a new virtualenv. But yesterday evening, I finally managed to make  my old virtualenv (the one working) work on my new computer, so there's no hurry. But I'd definitely like to understand what's happening there. I've been very surprised to realize that it did work when I ran it directly in the console.

BTW, I'm just realizing I might not have understood your previous question properly : it does run well in the console, but in PyCharm, it doesn't, debug or not debug. Although I believe the error message when in run mode was different.

0

Please sign in to leave a comment.