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

Add guide for working with Python on Windows #773

Open
wants to merge 44 commits into
base: main
Choose a base branch
from

Conversation

wookie184
Copy link
Contributor

@wookie184 wookie184 commented Sep 25, 2022

@netlify
Copy link

netlify bot commented Sep 25, 2022

Deploy Preview for pydis-static ready!

Name Link
🔨 Latest commit 0e1a5e2
🔍 Latest deploy log https://app.netlify.com/sites/pydis-static/deploys/637685004fc97900097914c9
😎 Deploy Preview https://deploy-preview-773--pydis-static.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@coveralls
Copy link

coveralls commented Sep 25, 2022

Coverage Status

Coverage remained the same at 100.0% when pulling 0e1a5e2 on add-windows-guide into 84c4a10 on main.

@wookie184 wookie184 marked this pull request as ready for review October 21, 2022 15:00
@wookie184
Copy link
Contributor Author

This still isn't quite finished, but it'd be good to get some reviews on the content. Please leave a comment if you think there's anything that should be added (you can take a look at the linked issues for ideas).

@mbaruh
Copy link
Member

mbaruh commented Oct 21, 2022

Thanks for this! A few immediate comments:

  • Should we maybe have a subdirectory for all of this? an issue might encompass several of those articles, and they're relatively scattered in the currently resulting list of guides..
  • Is "Don't use the py installer" a stance we want to take? I'm not a fan of it myself, but maybe it would be wiser to have a general page about it, with a section about caveats to watch out for.
  • In the PATH section, I think it's worth noting that if it contains several Python versions, using python in a terminal will invoke the top\first one.

@wookie184
Copy link
Contributor Author

* Should we maybe have a subdirectory for all of this? an issue might encompass several of those articles, and they're relatively scattered in the currently resulting list of guides..

Yeah, that would probably make sense

* Is "Don't use the py installer" a stance we want to take? I'm not a fan of it myself, but maybe it would be wiser to have a general page about it, with a section about caveats to watch out for.

WDYM by "py installer"?

* In the PATH section, I think it's worth noting that if it contains several Python versions, using `python` in a terminal will invoke the top\first one.

I mention that here https://deploy-preview-773--pydis-static.netlify.app/pages/guides/python-guides/python-on-windows/#the-advanced-method-editing-environment-variables, although maybe it should be moved to another point on that page or made more obvious?

You should now see a list of paths. Each path represents a folder that will be
searched for executables when looking up a command name in the terminal. The
paths are searched from top to bottom, and the first executable found matching
the name will be used. The system PATH variable has priority over the user one.

@mbaruh
Copy link
Member

mbaruh commented Oct 21, 2022

WDYM by "py installer"?

Oh sorry I meant the microsoft store page.

maybe it should be moved to another point on that page or made more obvious?

Ah I missed that. yeah maybe it should be in the form of "this is what you need to make sure of to make it work". EDIT: Also I would expect it to be in the section below where the instructions for adding to PATH are.

@wookie184
Copy link
Contributor Author

WDYM by "py installer"?

Oh sorry I meant the microsoft store page.

Well, I don't think we should recommend that people use it (due to said caveats), so i'm not sure what else would be on such a page (maybe how to uninstall it lol).

maybe it should be moved to another point on that page or made more obvious?

Ah I missed that. yeah maybe it should be in the form of "this is what you need to make sure of to make it work"

👍

@wookie184 wookie184 added the area: frontend Related to site content and user interaction label Oct 27, 2022
@wookie184 wookie184 added type: feature New feature or request s: needs review Author is waiting for someone to review and approve labels Nov 2, 2022
discretegames and others added 14 commits November 8, 2022 19:24
…/installing-and-using-python.md

Co-authored-by: wookie184 <[email protected]>
…/installing-and-using-python.md

Co-authored-by: wookie184 <[email protected]>
…/installing-and-using-python.md

Co-authored-by: wookie184 <[email protected]>
…/installing-and-using-python.md

Co-authored-by: wookie184 <[email protected]>
@shtlrs
Copy link
Member

shtlrs commented Nov 15, 2022

I think python-discord/bot#794 now has all the content of your PR combined there, isn't it ? Should we just keep one PR then ?

@discretegames
Copy link

I think python-discord/bot#794 now has all the content of your PR combined there, isn't it ? Should we just keep one PR then ?

I'm for that. I think python-discord/bot#794 is ready to be merged into here (or however that works exactly) if wookie signs off on it.

The "TODO: Add more screenshots" is done, and python-discord/bot#794 has articles that could be linked from most of the proposed !install, !windows-path, etc. tags (to supplement, not replace the tags).

Proofread, reorganized, and added to all the "Python on Windows" guides
Copy link
Member

@MrHemlock MrHemlock left a comment

Choose a reason for hiding this comment

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

Very well done. The main bulk of my gripes is the underselling of the py launcher. I feel like that should be the way we tell new users to use Python on Windows. Especially if people plan on having multiple different versions of Python on their rig.

Comment on lines +8 to +28
### When I run `python` in the terminal I get no result, or the Microsoft Store opens!

By default Windows has an alias for `python` in the terminal to guide you to install it from the [Microsoft
Store](https://apps.microsoft.com/store/search/python). We don't recommend installing Python from the Microsoft
Store, see why [here](../microsoft-store). To disable this alias, search "App execution aliases" in Windows search
and click on "Manage app execution aliases". In the list you should see two options with title "App Installer" and
descriptions `python.exe` and `python3.exe`. Disable both of them.

Note that if you are following instructions telling you to run a command starting with `python3`, those instructions are
intended for Unix/macOS systems. Try just using `python` instead.

If after doing this you have an issue with the Python command not being detected, see the question below.

### When I try and run my code with `python` in the terminal I get an error saying the command was not recognized

If you have not installed Python, you will need to do that. Follow our guide [here](../installing-and-using-python).

If you have installed python and are still having the issue, it is likely that you didn't check the "Add python.exe to
PATH" checkbox on the first page of the installer. See [our guide on adding Python to PATH](../putting-python-on-path)
for how to fix this. You can also use the `py` launcher instead of `python` by just replacing `python` in your command
with `py`. See [this guide](../installing-and-using-python/#the-py-launcher) for more information on that.
Copy link
Member

Choose a reason for hiding this comment

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

I would say that using the py launcher should be the first recommendation. Managing the aliases isn't necessary if you stick with using it. I'd say change the section a little where using py is the default recommendation, and another header saying "If you still want to using python instead of py

Copy link
Member

Choose a reason for hiding this comment

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

We should probably also address here or below how to install using py by doing py -m pip install [package_name_here].

for how to fix this. You can also use the `py` launcher instead of `python` by just replacing `python` in your command
with `py`. See [this guide](../installing-and-using-python/#the-py-launcher) for more information on that.

### I `pip` installed a package but when running my code I get a `ModuleNotFoundError`
Copy link
Member

Choose a reason for hiding this comment

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

As above, the usage of py -m pip install can be both helpful and important. If there is an issue with the PATH or other factors, python and pip may point to different versions. Using py -m pip install guarantees that whatever you pip install will go into that py version.

> `pip install` command in the VSCode terminal should work. If you are not using a virtual environment, you can use
> the `py` launcher to specify the installation you want to install to.

### I `pip` installed a command line program but it isn't recognized
Copy link
Member

Choose a reason for hiding this comment

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

Again, py launcher can help rectify some of this, including running some even when \Scripts isn't in the path. For example if you py -m pip install black, then try to just do black it may not work. But if you do py -m black it should.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This works well for some tools, but not others. For example, with pyinstaller you have to run py -m PyInstaller with that exact capitalisation - something that I don't believe is clearly documented anywhere, the docs just say to use pyinstaller directly so it's confusing when that doesn't work. There are also other tools that don't have any -m alternative that i've been able to find, like https://csvkit.readthedocs.io/en/latest/.

The py installer is nice, but it requires a certain amount of knowledge to know when and how to convert commands given in documentation to work with py. I think users generally want to be able to run commands in the way that docs give them.

It's annoying that stuff like this is such a minefield, there are a bunch of ways to make things work using just the py launcher - like by using pipx for tools and virtual environments when you want to just be able to python, but I wanted to try and keep this guide fairly simple.


### I get a `SyntaxError` when trying to run `pip`,`python`, or another command.

When you type `python` in the terminal you enter into the python REPL ([read-evaluate-print
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
When you type `python` in the terminal you enter into the python REPL ([read-evaluate-print
When you type `python` or `py` in the terminal you enter into the python REPL ([read-evaluate-print

you run `Python` code line by line without having to create a file. You also may have opened a Python REPL by clicking
on the Python App in your Start Menu.

General commands like `pip` and `python` should be run in your computer's normal terminal, that is, directly in
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
General commands like `pip` and `python` should be run in your computer's normal terminal, that is, directly in
General commands like `py`, `pip` and `python` should be run in your computer's normal terminal, that is, directly in


Our recommended way of installing Python on a Windows operating system is using the full installer from the official
[python.org Downloads page](https://www.python.org/downloads/) (from the big yellow button) using the default options,
except making sure to check the "Add python.exe to PATH" checkbox. Getting Python from the [Microsoft
Copy link
Member

Choose a reason for hiding this comment

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

I would highly recommend NOT adding python to PATH. The py launcher handles most if not all of that pathing. This will also prevent potential issues if you have multiple different versions of Python installed on your machine.

Comment on lines +52 to +54
3. Check the "Add python.exe to PATH" checkbox (the text may differ slightly depending on your installer). This will
make it so terminals can recognize commands like `python` and `pip`. (Read [this
guide](../putting-python-on-path) to learn more.)
Copy link
Member

Choose a reason for hiding this comment

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

As above, I recommend not adding to PATH.


[![Testing Python console](/static/images/content/python-on-windows/recommended_install_7.png)](/static/images/content/python-on-windows/recommended_install_7.png)

Or try the more usual way of running Python by typing `python` in a new terminal window to open up the Python
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Or try the more usual way of running Python by typing `python` in a new terminal window to open up the Python
Or try the more usual way of running Python by typing `py` or `python` in a new terminal window to open up the Python

[Here's a VSCode tutorial](https://code.visualstudio.com/docs/python/environments) and [here's
one for Pycharm](https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html).

The `venv` module used above comes with Python, but [Poetry](https://python-poetry.org/),
Copy link
Member

Choose a reason for hiding this comment

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

Possibly add pdm to the list as that one has been growing in popularity. https://pdm.fming.dev/

@@ -0,0 +1,254 @@
---
Copy link
Member

Choose a reason for hiding this comment

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

I would add a huge caveat about this section. Adding to PATH is not necessary when using the py launcher, and really shouldn't need to be done unless you just want to or you have a particular reason.

@jchristgit
Copy link
Member

Hi everyone, is there a way to help out with getting this pull request merged?

@jchristgit
Copy link
Member

Hi @wookie184. Did you find some time to look at the review comments, or is this up for grabs?

@hedyhli hedyhli added s: waiting for author Waiting for author to address a review or respond to a comment and removed s: needs review Author is waiting for someone to review and approve labels Jan 14, 2024
@wookie184
Copy link
Contributor Author

If we can make a decision on whether to guide the user to have python on their PATH, or just to have them use py, it would help to move this forwards.

I prefer getting the user to have python on ther PATH for the reasons I mention here #773 (comment), so personally I'm quite happy with leaving the PR mostly as is, though I could make some of the changes to make py a bit more visible as an option.

@wookie184 wookie184 added status: planning Discussing details s: needs review Author is waiting for someone to review and approve and removed s: waiting for author Waiting for author to address a review or respond to a comment labels May 24, 2024
@jchristgit
Copy link
Member

I prefer getting the user to have python on ther PATH for the reasons I mention here #773 (comment), so personally I'm quite happy with leaving the PR mostly as is, though I could make some of the changes to make py a bit more visible as an option.

I can't really comment on this as I do not run Python on Windows but your reasoning makes sense to me, and we should leave it mostly as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: frontend Related to site content and user interaction s: needs review Author is waiting for someone to review and approve status: planning Discussing details type: feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants