Skip to content

Update how to guide to install using pip and venv - #1338

Merged
willingc merged 11 commits into
python:mainfrom
willingc:update-guide
Nov 11, 2023
Merged

willingc merged 11 commits into
python:mainfrom
willingc:update-guide

Conversation

@willingc

@willingc willingc commented Nov 4, 2023

Copy link
Copy Markdown
Contributor

This PR makes the following updates:

  • remove all references to Python 2 and virtualenv and replace with a note at the top of the document
  • change env environment name to .venv which is more commonly used and less likely to be confused with environment variables
  • create 4 high level sections (pip, venv, install packages with pip, requirements files)

I view this PR as one of iteration of future iterations to improve individual documents in the guide.

@sinoroc sinoroc left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jeanas

jeanas commented Nov 4, 2023

Copy link
Copy Markdown
Contributor

It seems that this page:

https://packaging.python.org/en/latest/tutorials/installing-packages/#requirements-for-installing-packages

and this page:

https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/

are mostly duplicates. Right?

Of course feel free to improve them without merging them, I just wanted to point out that they could/should probably be.

@petsuter

petsuter commented Nov 4, 2023

Copy link
Copy Markdown

Before you can start installing or using packages in your virtual environment you’ll need to activate it.

While a virtual environment is activated, pip will install packages into that specific environment.

Activating a virtual environment will put the virtual environment-specific python and pip executables into your
shell's PATH.

Could these parts be updated as well? They are incorrect and actively misleading, leading to a lot of misunderstandings. A virtual environment can be used without activation. It depends on how / which pip is used. It would be fantastic if this guide could explain that in slightly more detail: Explicitly explain that activating is only (one way of) putting the the virtual environment-specific python and pip executables into the current shell's PATH. Specifying that path explicitly is also possible and often easier, preferred, clearer, more robust. The leaky abstraction "activation" and the lack of such an explanation is mystifying things unnecessarily, and leads to many problems and much confusion.

@willingc

willingc commented Nov 4, 2023

Copy link
Copy Markdown
Contributor Author

It seems that this page:

https://packaging.python.org/en/latest/tutorials/installing-packages/#requirements-for-installing-packages

and this page:

https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/

are mostly duplicates. Right?

That is true. One is a tutorial and this is the guide. According to Diataxis doc process, the guide is focused on one thing. I'm not updating the tutorial now but it can incorporate or refer to this after being merged.

@willingc

willingc commented Nov 4, 2023

Copy link
Copy Markdown
Contributor Author

Before you can start installing or using packages in your virtual environment you’ll need to activate it.

While a virtual environment is activated, pip will install packages into that specific environment.

Activating a virtual environment will put the virtual environment-specific python and pip executables into your
shell's PATH.

Could these parts be updated as well? They are incorrect and actively misleading, leading to a lot of misunderstandings. A virtual environment can be used without activation. It depends on how / which pip is used. It would be fantastic if this guide could explain that in slightly more detail: Explicitly explain that activating is only (one way of) putting the the virtual environment-specific python and pip executables into the current shell's PATH. Specifying that path explicitly is also possible and often easier, preferred, clearer, more robust. The leaky abstraction "activation" and the lack of such an explanation is mystifying things unnecessarily, and leads to many problems and much confusion.

Let me think about this a bit more. I think what you raise is interesting but perhaps belongs in a new Discussion/Explanation document instead of a "How To" guide. https://diataxis.fr/

I think that taking @Kwpolska's suggestion to rename the guide to "Install packages into a virtual environment using pip and venv" will help.

@petsuter

This comment was marked as resolved.

@Kwpolska

Kwpolska commented Nov 4, 2023

Copy link
Copy Markdown

This unfortunately is completely wrong. That will never install in the virtual environment. It is exactly showcasing a case of confusion caused by the "activating" concept. py is not affected by the "activated" PATH manipulation. It always uses the global python.

It seems to work for me, in both cmd and PowerShell:

C:\tmp>py -m venv testvenv

C:\tmp>testvenv\Scripts\activate

(testvenv) C:\tmp>py -m pip --version
pip 22.3.1 from C:\tmp\testvenv\Lib\site-packages\pip (python 3.11)

@petsuter

This comment was marked as resolved.

willingc and others added 2 commits November 4, 2023 16:48
Co-authored-by: sinoroc <5529267+sinoroc@users.noreply.github.com>
Co-authored-by: sinoroc <5529267+sinoroc@users.noreply.github.com>
@willingc

willingc commented Nov 6, 2023

Copy link
Copy Markdown
Contributor Author

I believe that I have addressed all feedback. Thanks for all of the reviews.

Co-authored-by: chrysle <fritzihab@posteo.de>
@sinoroc

sinoroc commented Nov 6, 2023 •

Copy link
Copy Markdown
Contributor

I think it can be merged as is...

I wonder though if it would not be better to have 3 tabs all the way. Sometimes unix and mac are merged into 1 tab sometimes not. So the auto switch of all tabs throughout the page does not work as expected.

@chrysle

chrysle commented Nov 8, 2023

Copy link
Copy Markdown
Contributor

Maybe link to the virtualenv stub now?

I wonder though if it would not be better to have 3 tabs all the way. Sometimes unix and mac are merged into 1 tab sometimes not.

I think this has been fixed recently? Add least I couldn't find examples any more...

@sinoroc

sinoroc commented Nov 8, 2023

Copy link
Copy Markdown
Contributor

I think this has been fixed recently? Add least I couldn't find examples any more...

https://python-packaging-user-guide--1338.org.readthedocs.build/en/1338/guides/installing-using-pip-and-virtual-environments/#prepare-pip

The "Prepare pip" section has 3 tabs.

@willingc

Copy link
Copy Markdown
Contributor Author

I'm going to go ahead and merge this. I appreciate all of the reviews and suggestions. Let's continue to iterate in separate PRs. ☀️

@willingc
willingc added this pull request to the merge queue Nov 11, 2023
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 11, 2023
@willingc
willingc added this pull request to the merge queue Nov 11, 2023
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 11, 2023
@willingc
willingc added this pull request to the merge queue Nov 11, 2023
Merged via the queue into python:main with commit 184f13f Nov 11, 2023
@willingc
willingc deleted the update-guide branch November 11, 2023 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants