PyDev, Python: Error importing OpenCV when debugging - python

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!

Related

pycharm does not connect to console with python3.8

I dont know why; but since python 3.8 has been released; I cant run pycharm console and it is always in the "being connected" status.
I have had no problem with python 3.7; since the console is opened immediately.
Here you can see that I have tried several times to run the console but I know, even if I wait a day; It does not connect to console; but when I change the interpreter from python3.8 to python3.7, The new consoles I open are all set up within a second.
The Error:
C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\_pydevd_bundle\pydevd_resolver.py:138: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if found.get(name) is not 1:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\pydevconsole.py", line 33, in <module>
from _pydev_bundle.pydev_console_utils import BaseInterpreterInterface
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\_pydev_bundle\pydev_console_utils.py", line 11, in <module>
from _pydevd_bundle import pydevd_thrift
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\_pydevd_bundle\pydevd_thrift.py", line 17, in <module>
from pydev_console.protocol import DebugValue, GetArrayResponse, ArrayData, ArrayHeaders, ColHeader, RowHeader, \
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\pydev\pydev_console\protocol.py", line 6, in <module>
_console_thrift = _shaded_thriftpy.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), "console.thrift"),
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_thriftpy\parser\__init__.py", line 29, in load
thrift = parse(path, module_name, include_dirs=include_dirs,
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_thriftpy\parser\parser.py", line 502, in parse
parser.parse(data)
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_ply\yacc.py", line 331, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_ply\yacc.py", line 1106, in parseopt_notrack
p.callable(pslice)
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_thriftpy\parser\parser.py", line 212, in p_struct
val = _fill_in_struct(p[1], p[3])
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_thriftpy\parser\parser.py", line 765, in _fill_in_struct
gen_init(cls, thrift_spec, default_spec)
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_thriftpy\thrift.py", line 103, in gen_init
cls.__init__ = init_func_generator(default_spec)
File "C:\Program Files\JetBrains\PyCharm 2019.1.3\helpers\third_party\thriftpy\_shaded_thriftpy\_compat.py", line 102, in init_func_generator
new_code = types.CodeType(len(varnames),
TypeError: an integer is required (got type bytes)
The Photo:
(source: techpowerup.org)
pycharm specs: pycharm professional version 2019.1.3
It works fine on PyCharm (Community) 2019.3.
PyCharm ships [PyPI]: thriftpy (for current version, it's a modified v0.3.8), as it needs it for different features (including the Python Console).
Python 3.8 came with a set of changes (one example is [Python]: PEP 570 -- Python Positional-Only Parameters) requiring changes in many of the existing (3rd-party) packages in order for them to work (for some of them, there's still WiP).
Apparently, ThriftPy is one of those packages that require changes. However it hasn't been maintained since 2016, so JetBrains keeps (a copy / fork ?) in their repository.
Anyway, the problem you're facing, was fixed by [GitHub]: JetBrains/intellij-community - PY-36069 Python console support for Python 3.8. Unfortunately, I couldn't find the issue on JetBrains.YouTrack, so I don't have any additional info about it (like when it was fixed, and so on).
What I can tell you (also mentioned at the beginning), is that it was fixed (works) in PyCharm (Community) 2019.3, so if you upgrade it, you should no longer have this problem.
A workaround (if upgrading is not an option) would be to apply the patch (in the commit URL) to your (local) _compat.py file. Check [SO]: Run / Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? (#CristiFati's answer) (Patching utrunner section) for how to apply patches (on Win).
Small mention: applying the reversed patch to my local file, made the problem visible.
Delete your code program and reload it from git or other svn, it would be ok for Pycharm 2021.2.3 Professional Edition.

PyCharm debugger fails with AttributeError

I cannot debug a Flask application in PyCharm. The application should run on port 5000: app.run(host="10.1.0.17", port=5000, debug=True). The console output is:
C:\Python\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 145.597.11\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 10498 --file "D:/TGM/SMS/SMS/Back .v2/wsgi.py"
pydev debugger: process 4108 is connecting
Could not connect to 127.0.0.1: 10499
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 145.597.11\helpers\pydev\pydevd.py", line 1523, in <module>
debugger.connect(host, port)
File "C:\Program Files (x86)\JetBrains\PyCharm 145.597.11\helpers\pydev\pydevd.py", line 317, in connect
self.initialize_network(s)
File "C:\Program Files (x86)\JetBrains\PyCharm 145.597.11\helpers\pydev\pydevd.py", line 304, in initialize_network
self.writer = WriterThread(sock)
File "C:\Program Files (x86)\JetBrains\PyCharm 145.597.11\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 392, in __init__
self.cmdQueue = _queue.Queue()
AttributeError: module 'queue' has no attribute 'Queue'
Process finished with exit code -1
I am using Python 3.5.1. What could be wrong?
The pydev debugger uses the same Pythonpath as the project you are trying to debug.
If you have any modules or packages with names of standard modules or packages, the pydev debugger might load your module instead of the standard module.
You probably have a module called queue in your projects directories, which causes this issue, since the python standard library also includes a module with that name.
try renaming your module, or changing your PYTHONPATH
PyCharm has the option to not include the projects root/source roots in the PYTHONPATH in Run > Edit Configurations. This could fix your problem, although you might need to fix some import statements in your project, if any of your import statements relied on this setting.

PyCharm debugger doesn't work

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.

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.

Trouble running an application made with PyInstaller, importing GTK--searching nonexistent directories

I am trying to create an executable of my Python application that uses PyGTK to make a GUI. I have a well-established, automated build process using Pyinstaller that has worked for me for a previous application. Suffice it to say that it calls the usual Makespec.py and Build.py with 32-bit Python 2.7, with Pyinstaller configured for 32 bits. The resulting 32-bit application works fine on my machine and another machine running Windows 7 64-bit, but fails on 32-bit Windows XP with this error:
C:\OutNav_0_64\OutNav_0.64>outnav
Traceback (most recent call last):
File "<string>", line 23, in <module>
File "C:\Pyinstaller-1.5\iu.py", line 436, in importHook
File "C:\Pyinstaller-1.5\iu.py", line 521, in doimport
File "C:\Users\462974\Documents\Local Sandbox\tools\utilities\Oni\build\pyi.win32\OutNav\outPYZ1.pyz/gtk", line 40, in
<module>
File "C:\Pyinstaller-1.5\iu.py", line 477, in importHook
File "C:\Pyinstaller-1.5\iu.py", line 495, in doimport
File "C:\Pyinstaller-1.5\iu.py", line 297, in getmod
File "C:\Pyinstaller-1.5\archive.py", line 468, in getmod
File "C:\Pyinstaller-1.5\iu.py", line 109, in getmod
ImportError: DLL load failed: The specified procedure could not be found.
The strange part is, there is no C:\Pyinstaller-1.5 directory on my machine or the one experiencing the error. I have no idea why it is attempting to run code from this nonexistent directory, or what the missing DLL is. Can anyone help me fold PyGTK into my application?
NOTE: The first line of the trace, line 23 in my program, is
import gtk
UPDATE: My manager successfully ran it on 64-bit Windows XP.
UPDATE 2: He was mistaken, it was 64-bit Windows 7. It has the same problem on his Windows XP installation.
Also, on the original machine it failed on, from the directory of the executable, I did this:
>>> import imp
>>> fp = open('gtk._gtk.pyd', 'rb')
>>> mod = imp.load_module('gtk._gtk', fp, 'gtk._gtk.pyd', ('.pyd', 'rb', 3))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
As far as I can tell, the .pyd file (which is in the format of a .DLL file) generated by pyinstaller on Windows 7 is incompatible with Windows XP. My solution was to simply recreate my build process on a Windows XP machine, which solved it to my satisfaction.

Categories

Resources