You need to tell Python what the dependencies are - there’s no way that Pip or any other tool can tell you, because the source code doesn’t actually have enough information. If you write import pandas then it could just as easily mean that you wanted to use the code in pandas.py (or in a pandas folder) from your own project. Even if we know that the dependency should come from installing something from PyPI, the name in your code doesn’t have to match the name that Pip and PyPI use. For example, we might want to pip install opencv-python in order to import cv2, or pip install Pillow in order to import PIL. There’s no way to predict that from the source code - you have to just know.
If you use pip freeze it will output a list of what has already been installed, and you can save that and reuse it to set up another copy of Python (or a virtual environment) with the same libraries.
If you are writing your own code and you want to figure out what you need to install in order to make it run, you need to do research. If you wrote import pandas because you want to use Pandas, then that should mean that you already know there is a Pandas website with documentation - and it will tell you what to install and how.
If you are trying to make someone else’s code run and you need to install something else first, it was the code author’s responsibility to fix that for you. When you see a project on Github it should have a pyproject.toml and/or setup.py file that is used for installing the project, which also means installing any libraries that it needs. Major projects on Github should also show a README or other documentation that explains how to use the code. (If you find something written by just some random person and you can’t figure out how to use it, it probably isn’t really meant for other people to use yet.)