0

I am django developer recently starting with webapp2 project. My question is how do I enter into debugging mode in webapp2 application using ipdb package as we do in django and flask.

my app structure:

helloapp
    - libs/
    - stylesheets/
    - templates/
    - .gitignore
    - app.yaml
    - index.yaml
    - main.py
    - webapp2.py

I have installed ipdb in libs folder using

sudo pip install -t github_projects/hellowebapp2/libs ipdb

main.py

from .libs import ipdb
class HelloWebapp2(webapp2.RedirectHandler):
    def get(self):
        import ipdb; ipdb.set_trace()

Error

/home/kishan/github_projects/hellowebapp2/main.py
ERROR    2016-11-07 06:48:01,566 wsgi.py:263] 
Traceback (most recent call last):
  File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/home/kishan/github_projects/hellowebapp2/main.py", line 12, in <module>
from .libs import ipdb
ValueError: Attempted relative import in non-package

Update

I followed this link now I get different error ImportError: No module named termios :(

Community
  • 1
  • 1
Kishan Mehta
  • 2,598
  • 5
  • 39
  • 61

1 Answers1

1

Its recommended that You should use virtualenvironments. Install virtualenvwrapper using pip.

pip install virtualenvwrapper

After that open your bashrc and insert relevant lines as mentioned in virtualenvwrapper docs. Then create a virtual environment.

mkvirtualenv myapp

install all python packages including webapp2 to your virtual environment.

pip install webapp2
pip install webob
pip install paste
pip install ipdb

This way, all your packages will be at one single location (/home/username/.virtualenvs/myapp)

And you can import any installed package you want without headaches from relative imports. And for missing termios, you may check SO Post

Community
  • 1
  • 1
cutteeth
  • 2,148
  • 3
  • 25
  • 45
  • Not working. Coming from django background this was the first thing I had tried. But webapp2 doesn't know the path of virtualenv and it needs all your third party packages inside your application folder as per my understanding. – Kishan Mehta Nov 07 '16 at 07:35
  • I just followed a tutorial here `https://media.readthedocs.org/pdf/webapp2/latest/webapp2.pdf#subsection.9.17.4`. Setup webapp2 using virtualenvs and in browser I am getting hello webapp2! as httpresponse as well as I was dropped into ipdb shell on importing and using ipdb.set_trace(). Also, its not about third packages, its all about pypi packages. `whatever you install in your virtual environment is handled by python rather than the framework you use`. HTH :) – cutteeth Nov 07 '16 at 07:48
  • Thanks but link you gave returns 404 error page not exists. check updated question. – Kishan Mehta Nov 07 '16 at 07:52
  • 1
    Posting link again. Because I also got a 404. But upon reloading it was working fine. `https://media.readthedocs.org/pdf/webapp2/latest/webapp2.pdf#subsection.9.17.4` . If you still cannot access that link try downloading pdf using `wget https://media.readthedocs.org/pdf/webapp2/latest/webapp2.pdf`. That will work for sure :) – cutteeth Nov 07 '16 at 07:56
  • Thanks but Its just showing how to create virtualenv that I know. Question is ipdb is not working. However I tried pdb and pdb works just fine but ipdb is much better than pdb so need to make it work. – Kishan Mehta Nov 07 '16 at 08:24
  • pdb works may be because you have installed it globally. Install ipdb to virtual environment since its better to bind package to virtual environment that you created and then import it. Process is simple, install all your packages to virtualenv and then import it. Nothing more. – cutteeth Nov 07 '16 at 09:11
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/127524/discussion-between-soup-boy-and-cutteeth). – Kishan Mehta Nov 07 '16 at 09:36