Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pip with python -m pip #100

Merged
merged 2 commits into from
Feb 2, 2023
Merged

Replace pip with python -m pip #100

merged 2 commits into from
Feb 2, 2023

Conversation

dstansby
Copy link
Contributor

Description

This is best practice, to make sure the pip being picked up matches the current python executable.

Type of change

  • Fixes or improves existing content

References

Final checklist:

  • My PR is the minimum possible work for the desired functionality
  • I have commented my code, particularly in hard-to-understand areas
  • I have added alt text to new images included in this PR

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jan 30, 2023
Copy link
Member

@melissawm melissawm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1!

@psobolewskiPhD
Copy link
Member

For my personal edification, can y'all give me a ELI5—or a link to read up?
🙏

@Czaki
Copy link
Contributor

Czaki commented Jan 30, 2023

For my personal edification, can y'all give me a ELI5—or a link to read up?

In general, all operating systems are using environment variable named PATH to store information where binaries are stored. You could preview it by calling echo $PATH in the terminal.

This path stores a list of directories that are checked in order from this variable to find where the variable is. After finding the first directory that contains the proper named executable with the proper name, the OS stops checking.

But for performance reasons system also cache search result.

So it may happen that, because of a mess in the PATH variable or some wrong working command, it may happen that calling pip may lead to running pip from a different environment than python -m pip (so different than python)

You may see a sample bug report here microsoft/vscode-python#8852

@brisvag
Copy link
Contributor

brisvag commented Jan 30, 2023

To add to the above:

  • calling python -m modulename is actually running module.__main__.py, which for pip is the command line interface
  • you might even not have pip in the active environment, which would basically guarantee that using pip install would run the system pip

@psobolewskiPhD
Copy link
Member

Thanks guys!
So if I follow, the reason I've not (to my knowledge) run into this is because of using conda envs and conda installs python and pip into the env?

@melissawm
Copy link
Member

@psobolewskiPhD probably, but it is still recommended (and I have personally found this to be a problem using conda as well on one or two occasions)

@Czaki
Copy link
Contributor

Czaki commented Jan 30, 2023

So if I follow, the reason I've not (to my knowledge) run into this is because of using conda envs and conda installs python and pip into the env?

maybe you directly execute instructions without using "shortcuts".

@dstansby
Copy link
Contributor Author

dstansby commented Jan 30, 2023

For what it's worth this is also what pip use in their docs: https://pip.pypa.io/en/stable/getting-started/

@brisvag
Copy link
Contributor

brisvag commented Jan 30, 2023

So if I follow, the reason I've not (to my knowledge) run into this is because of using conda envs and conda installs python and pip into the env?

I generally use pip for brevity, so it's not a common issue. But when it happens it's a pain to debug unless you're familiar with it, so it's good to have this in the docs :)

@psobolewskiPhD psobolewskiPhD merged commit 18bc467 into napari:main Feb 2, 2023
@dstansby dstansby deleted the pip branch February 2, 2023 11:47
@psobolewskiPhD psobolewskiPhD added this to the 0.4.18 milestone Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants