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/message/6LXLJ3WQBMFZVWSHW3SYSKAYF5X3K6KW/
To unsubscribe send an email topywikibot-le...@lists.wikimedia.org
_______________________________________________
pywikibot mailing list -- pywikibot@lists.wikimedia.org
Public archives at 
https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/IITFZOFU6J5L5GHVN7ZTAFPZSVGPY3LC/
To unsubscribe send an email to pywikibot-le...@lists.wikimedia.org

Reply via email to