简体   繁体   English

在pycharm中调试python代码

[英]Debugging python code in pycharm

This question is similar to this one. 这个问题与类似。 I am trying to debug pyethapp with the following configuration: 我正在尝试使用以下配置调试pyethapp

debug_app

The entry point is located in app.py . 入口点位于app.py中 The code runs fine when not being debugged, but once I launch the debugger the following exception is thrown: 未调试时,代码运行良好,但是一旦启动调试器,则会引发以下异常:

Failed to import scrypt. This is not a fatal error but does
mean that you cannot create or decrypt privkey jsons that use
scrypt

/usr/local/lib/python2.7/dist-packages/cffi/model.py:526: UserWarning: 'point_conversion_form_t' has no values explicitly defined; next version will refuse to guess which integer type it is meant to be (unsigned/signed, int/long)
  % self._get_c_name())
Traceback (most recent call last):
  File "/home/user/Utils/pycharm-community-2016.1/helpers/pydev/pydevd.py", line 1530, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/user/Utils/pycharm-community-2016.1/helpers/pydev/pydevd.py", line 937, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "app.py", line 27, in <module>
    from console_service import Console
  File "/home/user/Utils/pycharm-community-2016.1/helpers/pydev/_pydev_bundle/pydev_monkey_qt.py", line 71, in patched_import
    return original_import(name, *args, **kwargs)
  File "console_service.py", line 38, in <module>
    @inputhook_manager.register('gevent')
AttributeError: 'InputHookManager' object has no attribute 'register'

The solution suggested here (reinstalling ipython) did not solve the issue (it occurs only when debugging; the client works when run separately). 此处建议的解决方案(重新安装ipython)不能解决问题(仅在调试时会发生;客户端在单独运行时可以工作)。

Edit: 编辑:

Command line in output: 输出中的命令行:

/usr/bin/python2.7 /home/user/Utils/pycharm-community-2016.1/helpers/pydev/pydevd.py --cmd-line --multiproc --qt-support --client 127.0.0.1 --port 59087 --file app.py --profile testnet --data-dir testnetState/ run
warning: Debugger speedups using cython not found. Run '"/usr/bin/python2.7" "/home/user/Utils/pycharm-community-2016.1/helpers/pydev/setup_cython.py" build_ext --inplace' to build.
pydev debugger: process 20493 is connecting

Connected to pydev debugger (build 145.260)

Failed to import scrypt. This is not a fatal error but does
mean that you cannot create or decrypt privkey jsons that use
scrypt

/usr/local/lib/python2.7/dist-packages/cffi/model.py:526: UserWarning: 'point_conversion_form_t' has no values explicitly defined; next version will refuse to guess which integer type it is meant to be (unsigned/signed, int/long)
  % self._get_c_name())
Traceback (most recent call last):
  File "/home/user/Utils/pycharm-community-2016.1/helpers/pydev/pydevd.py", line 1530, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/user/Utils/pycharm-community-2016.1/helpers/pydev/pydevd.py", line 937, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "app.py", line 27, in <module>
    from console_service import Console
  File "/home/user/Utils/pycharm-community-2016.1/helpers/pydev/_pydev_bundle/pydev_monkey_qt.py", line 71, in patched_import
    return original_import(name, *args, **kwargs)
  File "console_service.py", line 38, in <module>
    @inputhook_manager.register('gevent')
AttributeError: 'InputHookManager' object has no attribute 'register'

This error is known to happen if you use old versions of IPython (in which indeed the method register was not yet implemented). 如果您使用的是旧版本的IPython(实际上尚未实现方法register ),则会发生此错误。 As you presumably use OSX, in which a default Python install is included, there might be some conflicting Ipython copies in your environment, different versions of which are called by the regular and debugging configurations? 当您大概使用OSX时(其中包括默认的Python安装),您的环境中可能会有一些冲突的Ipython副本,常规配置和调试配置会调用不同版本的Ipython?

This problem is probably resolved by moving the project to a virtual environment in which your root packages cannot interfere. 可以通过将项目移至您的根包无法干预的虚拟环境中来解决此问题。

To get rid of cython missing warning, run: 要摆脱cython missing警告,请运行:

python2  /.......git/liclipse/plugins/org.python.pydev_6.2.0.201711281546/pysrc/setu p_cython.py  build_ext --inplace

Finally the debug window stay clean of those dreaded warnings and cluttering. 最后,调试窗口将清除那些可怕的警告和混乱情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM