Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python module resolution

I have a question about the command python -m pip install …
Reading the documentation, it shows that the -m flag/option is used to identify a python module, the moudle is resolved by searching in the sys.path entries. In the above command, are we essentially asking the interpreter to search for pip in the sys.path? I located pip and it seems to be an executable and not a module, so does the -m flag also work for executables? Provided their locations are listed in the system path entries?

enter image description here

i searched for the pip file and found that its an executable

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There are both. The is a pip module, somewhere like .../site-packages/pip, and the top-level executable script. The -m does run a module as a main script, but it can also run a package as main script if it has a special file name __main__.py in it. The pip package has this. So the package can be run as if it were the main script. Python will run what is in that __main__.py file.

This is a good way to target a specific pip for a specific version of Python, if you have more than one version of Python installed on your system.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading