Hi all,
I want to create new anki profiles on need bases.
how can I create a new anki user profile from python code?
which command to use?
could you please help?
Hi all,
I want to create new anki profiles on need bases.
how can I create a new anki user profile from python code?
which command to use?
could you please help?
Try:
mw.pm.create("My Profile")
thank you. I am getting an error âmwâ is not defined
I added the following import also still
from aqt import mw
now the error is âcannot import name âmwâ from âaqtââ
Whatâs your environment? And how are you installing the aqt package? The code only works in an add-on.
My envionment is my laptop, developing a web application and I installed aqt from command line with "pip install " command.
My code is like below
from aqt import mw
mw.pm.create(âsdfffâ)
the error I am getting is No module named âPyQt6.QtWebEngineCoreâ
You probably have to create a ProfileManager object and avoid using mw
then, since that doesnât work outside add-ons. Check the source here: anki/qt/aqt/profiles.py at 312d396505a4806b76b74dfda6d276ec595e17ed ¡ ankitects/anki ¡ GitHub
Thank you.
when I try that I am getting below error
"ModuleNotFoundError: No module named âPyQt6.QtWebEngineCoreâ
I have PyQt6 already installed actually.
from aqt import *
ProfileManager.create(âfsdfâ)
When I type the below line
âfrom PyQt6â and when I press Dot, I do not see QtWebEngineWidgets in the available list
Does installing aqt using pip install aqt[qt6]
help?
Hi Adbo,
I tried that, but that did not help. Still the same error
thank you
Sorry, I meant pip install aqt[qt6]
.
great, that worked but now I have another issue
it expects 2 parameters
My code is below lines
import sys
from aqt import *
ProfileManager.create(âmY profileâ)
now the error is âProfileManager.create() missing 1 required positional argument: ânameââ
from aqt.profiles import ProfileManager
pm = ProfileManager(ProfileManager.get_created_base_folder(None))
pm.setupMeta()
pm.create("my profile")
Thanks abdo,
I ran the command, but after running those commands, anki is not opening.
I had to completely clean uninstall and reinstall Anki to get it back working.
So running the command, is broke anki with error
AttributeError: âNoneTypeâ object has no attribute âexecuteâ
But after complete uninstall/install, it seemed working, I will double check and let you know, thank you.
Regards
Ravindar
Hi abdo, once the profile got created, the corresponding folder is not being created.
How can I make the folder be created when the profile is created?
pm.profileFolder() command is not helping either because it only creates a empty folder but not the content inside.
I need the operation exactly when we do âswitch profileâ in anki, that will create the folder and itâs contents inside
Use this to create the profile folder after running the previous code snippet:
from anki.collection import Collection
col = Collection('profile_name/collection.anki2')
Thanks abdo,
unfortunately, That command throws error
anki.errors.DBError: DbError { info: âSqliteFailure(Error { code: CannotOpen, extended_code: 14 }, Some("unable to open database file: âŚmyprofile7\\\\collection.anki2"))â, kind: Other }
I missed the step of creating the folder. This should work:
import os
profile_path = os.path.join(pm.base, profile_name)
os.mkdir(profile_path)
col = Collection(os.path.join(profile_path, "collection.anki2"))
Lovely, that worked pretty good, Thanks abdo
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.