I have an own package with path c:\Pywikibot\scripts\userscripts\huwiki.
When I use saved scripts, import huwiki works fine.
Either I call python from Windows command line from c:\Pywikibot, and import pywikibot, or I call python pwb.py shell from the same directory, import huwiki will work in neither cases. So how can I use it from interactive environment?
Hi Bináris,
Python uses the directories in `sys.path` to determine where to find files to import. Normally that includes the local directory (".") and a bunch of other folders. In the case of "pwb.py shell" the "scripts" directory is also included:
valhallasw@tools-bastion-12:~/src/pywikibot-core$ /home/valhallasw/.local/bin/uv run pwb.py shell Welcome to the Pywikibot interactive shell!
import sys sys.path
['/mnt/nfs/labstore-secondary-tools-home/valhallasw/src/pywikibot-core/pywikibot/scripts', '/mnt/nfs/labstore-secondary-tools-home/valhallasw/src/pywikibot-core', '/usr/lib/python311.zip', '/usr/lib/python3.11', '/usr/lib/python3.11/lib-dynload', '/mnt/nfs/labstore-secondary-tools-home/valhallasw/src/pywikibot-core/.venv/lib/python3.11/site-packages', '__editable__.pywikibot-10.0.0.dev1.finder.__path_hook__', '/mnt/nfs/labstore-secondary-tools-home/valhallasw/src/pywikibot-core/pywikibot/families']
To import scripts in subdirectories of /scripts, you can either:
- adjust sys.path to add the directory you're looking for, or - make sure that there is an __init__.py in /scripts/userscripts/huwiki, then import it as "userscripts.huwiki"
Cheers,
Merlijn / valhallasw
On 17/01/2025 09:40, Bináris wrote:
I have an own package with pathc:\Pywikibot\scripts\userscripts\huwiki.
When I use saved scripts, import huwiki works fine.
Either I call python from Windows command line from c:\Pywikibot, and import pywikibot, or I callpython pwb.py shell from the same directory, import huwiki will work in neither cases. So how can I use it from interactive environment?
-- Bináris
pywikibot mailing list --pywikibot@lists.wikimedia.org Public archives athttps://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email topywikibot-leave@lists.wikimedia.org
Merlijn van Deen (valhallasw) valhallasw@arctus.nl ezt írta (időpont: 2025. jan. 19., V, 14:41):
- make sure that there is an __init__.py in /scripts/userscripts/huwiki,
then import it as "userscripts.huwiki"
That's it, this was the question! Thank you very much!