Anki Forums

Import window opens when running in Debug mode in Pycharm

Hi all,

I am using Pycharm for add-on development. When I run anki in debug mode (but not simply run mode), a deck import window always opens on startup.

I seemed to have traced it to the onappMsg() call in aqt/main.py. The variable is_addon is set to False, so self.handleImport(buf) is called at the end of the function:

# import / add-on installation
if is_addon:
    self.installAddon(buf)
else:
    self.handleImport(buf)

Would anyone be able to help me understand why this is occurring and if there is a fix I can make to the debug configuration?

This is most likely because you’re passing an argument to the run script that Anki interprets as a file to import/add-on to install; like this .\run something.
Maybe you meant to point Anki to a different base folder/profile but forgot to pass the -b/-p flag?

See aqt/__init__.py.

2 Likes

Thanks for the reply! I had both -b and -p flags set, but even after removing them, the import window is still appearing, unfortunately. I tried removing the default ‘PYTHONUNBUFFERED=1’ environment variable, as well, to no avail.

If you print sys.argv in the __init__.py file you should be able to see what argument is being passed in.

Thanks very much for the tip. Printing sys.argv gives me:
[’/path_to_anki…/anki/qt/runanki’]

I also started with a new profile folder (ie. without any existing addons or profiles), but I’m unfortunately still having the Import window pop up on startup.

Hmm, not sure what pycharm is doing differently there, as there don’t appear to be extra arguments. Maybe you can work around it by using the wheels mentioned in the other post.

Ya, it’s quite strange as it only occurs when running in debug mode, not the regular run mode in Pycharm. Thanks for the tips and I’ll post an update if I manage to figure out a solution.

I think I managed to trace the issue a bit better.

When running Pycharm in debug mode (but not regular run mode), the function onAppMsg(self, buf:str) in main.py gets called, with buf = '/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevd.py'.

Further down in the function, self.handleImport(buf) is then called, triggering the import window.

I can just comment out some of the code for now, but I’ll see if I can figure out a fix with the configuration of PyCharm.

1 Like