PyCharm debugger doesn't work - python

I just downloaded PyCharm community edition and every time I try to debug any Python program in PyCharm, I get this error:
C:\Python31\python.exe "C:\Program Files (x86)\JetBrains\PyCharm Community
Edition 2016.1\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 59207 --file C:/Users/Gal/PycharmProjects/untitled/test.py
pydev debugger: process 5388 is connecting
Connected to pydev debugger (build 145.260)
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1\helpers\pydev\pydevd.py", line 1530, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1\helpers\pydev\pydevd.py", line 937, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 11, in execfile
stream = tokenize.open(file) # #UndefinedVariable
AttributeError: 'module' object has no attribute 'open'
and a python file named "_pydec_excecfile.py" opens:
#We must redefine it in Py3k if it's not already there
def execfile(file, glob=None, loc=None):
if glob is None:
import sys
glob = sys._getframe().f_back.f_globals
if loc is None:
loc = glob
# It seems that the best way is using tokenize.open(): http://code.activestate.com/lists/python-dev/131251/
import tokenize
stream = tokenize.open(file) # #UndefinedVariable
try:
contents = stream.read()
finally:
stream.close()
#execute the script (note: it's important to compile first to have the filename set in debug mode)
exec(compile(contents+"\n", file, 'exec'), glob, loc)
How can I fix it?

I had a similar situation in a project that had a file named 'tokenizer.py'.
While trying to debug a different Python code in the same project (even in a different file) I got the following error output:
Traceback (most recent call last):
File "C:\Programs\PyCharm\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Programs\PyCharm\plugins\python-ce\helpers\pydev\_pydev_imps \_pydev_execfile.py", line 11, in execfile
stream = tokenize.open(file) # #UndefinedVariable
AttributeError: module 'tokenize' has no attribute 'open'
I could run the code, but not debug it. Then I found a discussion at link, the idea there was that a module in the code shadowed some top level package required by the debugger. I renamed the 'tokenizer' module, and debugging was possible again.
This seems to be the recipe: try to rename the module mentioned in the error output.

Related

ImportError: DLL load failed: The specified module could not be found - PyCharm

So I've been trying to switch to PyCharm this week and using some of my old code has not been working out. I am using the base anaconda environment as the interpreter, and the following code
import openpyxl
import numpy as np
And then some basic code on opening a sheet and creating arrays with the rows and columns. AFAIK this is an import problem related to a missing DLL, but nothing more than that. Here's the error:
Traceback (most recent call last):
File "C:\Users\nikol\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2961, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-a51a1395fac2>", line 1, in <module>
runfile('C:/Users/nikol/Desktop/APO A1P2/Code/make_excel.py', wdir='C:/Users/nikol/Desktop/APO A1P2/Code')
File "C:\Program Files\JetBrains\PyCharm 2019.2.3\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2019.2.3\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/nikol/Desktop/APO A1P2/Code/make_excel.py", line 2, in <module>
import numpy as np
File "C:\Program Files\JetBrains\PyCharm 2019.2.3\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\nikol\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\Program Files\JetBrains\PyCharm 2019.2.3\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\nikol\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
from . import _mklinit
File "C:\Program Files\JetBrains\PyCharm 2019.2.3\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: DLL load failed: The specified module could not be found.
Greatly appreciate any and all feedback! Thanks!
SOLVED!
Frustrating working with PyCharm, but here it is, step by step so a newbie like me can solve it later on. Note I am using Windows 10
Find your anaconda directory, for me it was:
C:\Users\<myusername>\Anaconda3\
THEN:
Right click my PC > Properties > Advanced system settings > Environment variables
Under System variables find the one named "Path"
And in it, you have to ADD the following paths (note your anaconda directory may differ!!!):
C:\Users\<myusername>\Anaconda3\Scripts\
C:\Users\<myusername>\Anaconda3\Library\
C:\Users\<myusername>\Anaconda3\Library\bin\
C:\Users\<myusername>\Anaconda3\Library\mingw-w64\bin\
Click OK and restart PyCharm. Worked for me!
There is a bug in pycharm on windows that the program does not run as administrator. So if you create a project and pycharm is not runner as administrator, your project will not have access to your system files forever and this is an issue. Try to recreate your project and environment when you run pycharm as admin.

Debugging python code in pycharm

This question is similar to this one. I am trying to debug pyethapp
with the following configuration:
The entry point is located in 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).
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). 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?
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:
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.

Module not found when debugging

I am running a Python client using PyCharm. If I just run it, PyCharm simply calls:
C:\Python27\python.exe E:/faf/client/src
and everything is fine.
These are my settings:
If I want to debug it, PyCharm calls:
C:\Python27\python.exe "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 5.0.2\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 52948 --file E:/faf/client/src
and the result is that the modules which are in fact there cannot be included
pydev debugger: process 5092 is connecting
Connected to pydev debugger (build 143.1184)
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 5.0.2\helpers\pydev\pydevd.py", line 2407, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 5.0.2\helpers\pydev\pydevd.py", line 1798, in run
launch(file, globals, locals) # execute the script
File "E:/faf/client/src\__main__.py", line 29, in <module>
import config
ImportError: No module named config
What do I have to do to be able to debug this thing?
I had to click on the src directory and add it as source folder (Mark Directory As -> Source Root). No apparent thing changed like e.g. the way the python command got called.
So if you have a similar looking problem try to do the same.
I resolved this issue for myself by adding an init.py in the folder of the module I was trying to import.

PyDev, Python: Error importing OpenCV when debugging

I am having problens debugging my code. When I use OpenCV by importing cv2 I get the following output:
pydev debugger: process 8272 is connecting
Connected to pydev debugger (build 141.1899)
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.5.3\helpers\pydev\pydevd.py", line 2358, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.5.3\helpers\pydev\pydevd.py", line 1778, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:/work/210 Python/6 imagingSource/test.py", line 3, in <module>
import cv2
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.5.3\helpers\pydev\pydev_monkey_qt.py", line 71, in patched_import
return original_import(name, *args, **kwargs)
ImportError: DLL load failed: Die angegebene Prozedur wurde nicht gefunden.
So some DLL can not be loaded. I do not get the error when I normally run the file.
I checked the run and debug environments with the os package. They are almost the same, differing only in some additional entries for the pydev debug environment. I think I also checked whether or not a 64bit interpreter is being used by executing sys.maxsize in both environments. They return the same values so I guess they are both the same - 64bit.
So I am without a clue what could be the cause of this issue. Does anyone have an idea?
Thanks in advance!

App Engine Python won't start

I don't know what changed, but suddenly none of my Python App Engine projects will start on my PC. They start on my MacBook just fine, so there's something about the installation on my PC that's messed up. I've tried going back to 1.8.8, but that doesn't work. I've also tried using a fresh Python installation, but that didn't work. I've even tried using port 8080 (I usually use port 80, as I run the app launcher as admin).
This is what shows up in the error log when I click start on one of my projects:
2014-02-05 10:42:24 Running command: "['c:\\users\\jonathan\\appdata\\local\\enthought\\canopy\\user\\scripts\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=80', '--admin_port=8000', 'C:\\Users\\jonathan\\My Repositories\\my-project']"
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 197, in <module>
_run_file(__file__, globals())
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 193, in _run_file
execfile(script_path, globals_)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 32, in <module>
from google.appengine.tools.devappserver2.admin import admin_server
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\admin\admin_server.py", line 29, in <module>
from google.appengine.tools.devappserver2.admin import console
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\admin\console.py", line 22, in <module>
from google.appengine.tools.devappserver2 import module
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\module.py", line 69, in <module>
from google.appengine.tools.devappserver2 import wsgi_server
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\wsgi_server.py", line 31, in <module>
from cherrypy import wsgiserver
File "C:\Program Files (x86)\Google\google_appengine\lib\cherrypy\cherrypy\__init__.py", line 278, in <module>
_pydoc._builtin_resolve = _pydoc.resolve
AttributeError: 'module' object has no attribute 'resolve'
2014-02-05 10:42:32 (Process exited with code 1)
Also, I'm using Windows 7 x64. My original installation of Python is from Enthought x64, but I did try using the basic x64 Python as well. As mentioned, I downgraded from 1.8.9 to 1.8.8, to no avail.
From a quick Google search, other users are suggesting it's a bug in pyvenv. Since not very many people are still using CherryPy, and it seems to only manifest itself in whatever CherryPy is doing there, that's probably it.
Bug the gist is that somewhere, only on Windows, you have a pydoc.py file which is being imported instead of the standard library's pydoc file.
So, find the offending pydoc.py file in your import path, and rename it. You can most likely find it by doing something like this:
import pydoc
print pydoc.__file__

Categories

Resources