This problem of not understanding how
This problem has been asked here or other places many times for all OS.
From Python Doc The initialization of the sys.path module search path
If want to add some folders permanently it only takes a minute,using PYTHONPATH.
![[Image: v9I7ZQ.png]](https://imagizer.imageshack.com/v2/800x600q70/922/v9I7ZQ.png)
Other ways eg poetry it will make a package automatic with
This way will be easier if eg one day want to add package to PyPi,then just
Can just ad poetry later if have make a package and it's more serious project like want it on PyPi.
sys.path
work can arise on all OS Windows,Linux,Mac.This problem has been asked here or other places many times for all OS.
From Python Doc The initialization of the sys.path module search path
If want to add some folders permanently it only takes a minute,using PYTHONPATH.
![[Image: v9I7ZQ.png]](https://imagizer.imageshack.com/v2/800x600q70/922/v9I7ZQ.png)
Other ways eg poetry it will make a package automatic with
pyproject.toml
and test folder. This way will be easier if eg one day want to add package to PyPi,then just
poetry publish
.Can just ad poetry later if have make a package and it's more serious project like want it on PyPi.
G:\ λ poetry new my_package Created package my_package in my_package G:\ λ cd my_package\ G:\my_package λ ls my_package/ pyproject.toml README.md tests/ G:\my_package\my_package λ ls __init__.py __pycache__/ foo/ main.pyUse it two way.
G:\my_package λ poetry run python Python 3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from my_package import bar, main >>> >>> bar.answer_to_life() 42 >>> main.main_func() 'Now in main func' >>> exit()Or poetry will create a virtual environment automatic with
poetry shell
.G:\my_package λ poetry shell Creating virtualenv my-package-Jw3aWtBz-py3.12 in C:\Users\Tom\AppData\Local\pypoetry\Cache\virtualenvs Spawning shell within C:\Users\Tom\AppData\Local\pypoetry\Cache\virtualenvs\my-package-Jw3aWtBz-py3.12 (my-package-py3.12) G:\my_package>python Python 3.12.2 (tags/v3.12.2:6abddd9, Feb 6 2024, 21:26:36) [MSC v.1937 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from my_package import bar, main >>> >>> bar.answer_to_life() 42 >>> main.main_func() 'Now in main func' >>> exit()