Can't open file on pythonpath

I use Linux, OpenSuse and in my .login, as well as in .bashrc, file is written this line:
setenv PYTHONPATH /home/alen/miniforge:/home/alen/python:/home/alen/python/book:/home/alen/sunpy
When I try the following:

/home/alen> python
Python 3.12.6 | packaged by conda-forge | (main, Sep 22 2024, 14:16:49) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import test
Hello file world!
>>> f = open('test.py')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'test.py'

the result is that it can not open the file, but can execute it. Why is that?

PYTHONPATH is the search locations for Python libraries. open("anything") isn’t looking for a library. It just opens files by name and you’ve given it a relative path so it’s only going to look in your current working directory.

It’s the same as when cat test.py doesn’t go looking through PYTHONPATH (or any other environment variable) for files.

FYI It is usually considered a problem to set up a PATH, PYTHONPATH, etc of any kind in your .bashrc.
This is because you prevent it being changed interactively.

Thank you for clarification Brenainn, Barry!
Is there a way to make a open(‘filename’) to search for files, so that
I don’t have to give absolute path? I worked previously with IDL, and
it could be done there.

Would:

import test
open(test.__file__)

do? I can’t think of and good reason why you’d want to open() a Python script so I don’t know what your constraints are.

Many thanks Brenainn!
It worked! I am still learning Python and this was just an exercise from a
book. I also wanted to test if my path was good.
Kind regards,
Alen