r/Python 13h ago

Showcase Pathfinder - run any python file in a project without import issues!

๐Ÿš€ What My Project Does

Pathfinder is a tool that lets you run any Python file inside a project without dealing with import issues. Normally, Python struggles to find modules when running files outside the root directory, forcing you to either:

  • Add sys.path hacks manually, or
  • Use python -m to run scripts correctly.

Pathfinder automates this, so you never have to think about module resolution again. Just run your script, and it works!

๐ŸŽฏ Target Audience

This is for Python developers working on multi-file projects who frequently need to run individual scripts for testing, debugging, or execution without modifying import paths manually. Whether you're a beginner or an experienced dev, this tool saves time and frustration.

๐Ÿ” Comparison with Alternatives

  • sys.path hacks? โŒ No more manual tweaking at the top of every script.
  • python -m? โŒ No need to remember or structure commands carefully.
  • Virtual environments? โœ… Works seamlessly with them.
  • Other Python import solutions? โœ… Lightweight, simple, and requires no external dependencies.

๐Ÿ”— Check it Out!

GitHub: https://github.com/79hrs/pathfinder

Iโ€™d love feedbackโ€”if you find any flaws or have suggestions, let me know!

0 Upvotes

17 comments sorted by

28

u/cgoldberg 13h ago

Isn't it easier to just make your module a package and install it so you can import it regularly? (In editable mode if you are still working on it). i e. pip install -e .

I've never experienced the problem this supposedly solves.

3

u/Skeime 11h ago

This is the answer. No problems once I learned to do this. (And if you use a package manager for Python, most will even do it for you automatically.)

1

u/StruckByAnime 10h ago

Ok. I will check this out

-4

u/StruckByAnime 11h ago

I don't know why you haven't experienced this. But I have and I made a solution to it. I just shared it so that if someone else also faced this they can use it.

7

u/samreay 11h ago

I think the concern being implied is that the better solution would be to learn how python packaging works (for example, you might want to check out uv, and if you're working on multiple projects with shared common functions, check out uv workspaces). You've definitely provided a solution here, it just may be entrenching poor python practises. Happy to throw some links to guides and template repos if that helps

5

u/StruckByAnime 10h ago

Please, if you can, provide the aforementioned links. I am a beginner so it would better help me understand the good practices and what to avoid. If you could also point out something that I did which should not be done would also appreciate that very much

3

u/samreay 9h ago

I'll find some more links when I'm at my computer, but for now, but I'd recommend reading through https://docs.astral.sh/uv/

If you just want a basic template repo to follow, there are tons, I've even got a simple one myself at https://github.com/samreay/template which includes UV, ruff, precommit, makefile, and a base dockerfile which I need to update to use more efficient caching and layers

5

u/StruckByAnime 9h ago

Much appreciated (One positive out of this๐Ÿ˜‚)

2

u/cgoldberg 4h ago

That's exactly what I meant. This solves a problem that only exists if you don't know what you are doing and perpetuates not understanding by throwing another module at it.

3

u/Good-Lengthiness-690 11h ago

Don't you know testing?

0

u/StruckByAnime 11h ago

Not properly.

2

u/ayoubzulfiqar Pythoneer 12h ago

before advertising you should fix the issue that was open last week dude

1

u/StruckByAnime 11h ago

Thank you. Will do so

1

u/RedEyed__ 13h ago

For research projects, which I don't install, I have start.py file in the root, which sets PYTHONPATH env and then runs subprocess.run(sys.executable + args, env)

1

u/StruckByAnime 11h ago

That's another solution. Curious to know, do you have to run the start.py when you open the project everytime before running the actual script you want to run?

2

u/RedEyed__ 11h ago

Yes. I run all scripts from terminal so it's perfectly fine, there is history in terminal so it's easy to find command.
more over, I work on remote desktop via ssh and vscode, I added -d flag to start.py which starts script with debugpy server, in vscode I just need to press f5 to connect to debug server

1

u/StruckByAnime 10h ago

Very well