diff options
Diffstat (limited to 'pydis_site')
10 files changed, 103 insertions, 102 deletions
diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/putting-python-on-path.md b/pydis_site/apps/content/resources/guides/python-guides/windows/putting-python-on-path.md index 25bf8d8f..0627516b 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/putting-python-on-path.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/putting-python-on-path.md @@ -3,4 +3,104 @@ title: Putting Python on Path description: How to make sure Python is properly on the Windows Path environment variable --- +If you're on Windows and know you have [Python installed from python.org](https://www.python.org/downloads/) ([our +recommended way](../installing-python.md)) but you're still getting errors like + +```text +pip : The term 'pip' is not recognized as the name of a cmdlet, function, script file, or operable program. +``` + +when trying to run a [pip](https://pip.pypa.io/en/stable/) or [pyinstaller](https://pypi.org/project/pyinstaller/) +command, or running `python` [unexpectedly opens up the Microsoft +Store](../microsoft-store.mdconfusing-app-execution-alias-behaviour), the issue is likely that your Windows Path +environment variable is improperly configured for Python. This just means Windows doesn't know how to find your Python +installation. + +The Path (or PATH) environment variable is what Windows uses to locate executables needed on the command line. Whenever +you type a command name in your terminal, like `python` or `pip`, the terminal looks for an exe with the same name in +the folders listed in the Path, so the command can be run. + +The [Python installer](https://www.python.org/downloads/) provides an option to add Python to your Path automatically, +although it is not checked by default so many people miss it: + + + +But don't worry, you can have the installer add it after the fact, or add it yourself! Continue on just below to the +[safe method](#safe-method-let-the-installer-add-python-to-path) to have the installer put Python on Path for you, or, +if you want to learn a handy Windows programming skill, skip to the [advanced +method](#advanced-method-manually-edit-the-path) that explains how to edit the Path manually. + +## Safe method: Let the installer add Python to Path + +The easiest and safest way to add Python to Path is by rerunning the installer. For this you will need the same +installer you used to install Python, which you can download again if needed from +[python.org](https://www.python.org/downloads/windows/), or it may still be in your Downloads folder (it's a file like `python-3.11.0-amd64.exe`). + +Once you have it, here are the steps to modify the installation to add Python to Path: + +1. Run the installer by double clicking it. + +  + +2. Select "Modify". (If you don't see the "Modify/Repair/Uninstall" screen then you likely have the wrong installer.) + +  + +3. Hit "Next" to move past the "Optional Features" screen. + +  + +4. Check "Add Python to environment variables" on the "Advanced Options" screen. + +  + +5. Hit install! + +  + +Then, after a moment, it should say "Modify was successful" and you can close the installer, and Python should now be on your Path! **You will need to restart any terminals or editors you have open before they detect the change.** + +(These steps are for the Python 3.11 installer may differ slightly for other versions. Also, for step 1, if preferred, you can find your Python installation in the "Apps & features" Windows settings and hit "Modify" there, but you will still need to locate the installer exe at step 5 if it's not already in Downloads.) + +To check that it worked, open a terminal — Command Prompt, Powershell, an IDE-integrated terminal, [Windows Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701), whichever you prefer, just _not_ the Python terminal with the `>>>` prompt — and run + +```text +python -V +``` + +and then + +```text +pip -V +``` + +and you should see the versions of Python and pip that you just added to Path: + + + +You can also run Python with `python`, and then after `>>>` in the Python REPL, run + +```py +import sys; print(sys.executable) +``` + +to see that the exact executable that is currently running Python is what you expect: + + + +(Type `exit()` from here to go back to the normal terminal.) + +<!-- TODO mention that py may open a different version and link to py launcher guide. --> + +Of course your username will probably not be "r" like mine is, and your executable path may differ from +`C:\Users\<user>\AppData\Local\Programs\Python\Python311` depending on where you chose to install Python and what +version you have. The last folder will be `Python310` for Python 3.10, `Python39` for Python 3.9, etc. But those +differences don't matter if `python` and `pip` and other things like `pyinstaller` (if you've pip installed it) now work +for you! + +Hopefully things are indeed working, _however_, it is possible that, due to having multiple Python versions, or other mixups, +the commands are still not behaving how you expect. If so, read on to learn how to manually edit the Path environment variable. It's really not that hard and a super useful Windows skill to know for more than just Python. + +## Advanced Method: Manually edit the Path + TODO!!! diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/py-launcher.md b/pydis_site/apps/content/resources/guides/python-guides/windows/py-launcher.md index 416d13ec..673a1759 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/py-launcher.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/py-launcher.md @@ -1,8 +1,10 @@ --- title: The py Launcher on Windows -description: Common commands and usage of the 'py' Python launcher +description: Common commands and usage of the Windows "py" Python launcher --- +When you install Python on Windows fron + TODO!!! rewrite/rearrange to be all about the py command ## The py launcher @@ -47,104 +49,3 @@ all. I would recommend having your "main" python version on path so you can invoke it with `python` if you want to, and then use `py` whenever you want a different version. The full documentation of the `py launcher` can be found [here](https://docs.python.org/3/using/windows.html#python-launcher-for-windows) - -## Virtual Environments - -Virtual environments, (aka `venvs`), are a way of letting each of your projects -run in it's own python environment so different projects can have different -versions of the same dependencies. This means that a `pip install` to your main -Python will not affect a project where you're using a virtual environment. - -For information on how to create and activate a virtual environment check out -[this guide](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment) - -If your editor/IDE has handling for venvs, it's worth looking into how it works. -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). -[Poetry](https://python-poetry.org/) and -[Pipenv](https://pipenv.pypa.io/en/latest/) are both popular tools for managing -dependencies and virtual environments. - -## Changing PATH - -PATH is the system variable that Windows uses to locate executables needed on -the command line. Whenever you type a command name in your terminal, for example -`python` or `pip`, the terminal will look it up in the PATH to try and find out -what executable that command refers to, so it can be run. - -The Python installer provides an option to add `python` to your PATH, although it -is not checked by default so many people miss it. Don't worry if you forgot to select -this though, you can add it after installing: - -### The safe method: through the installer - -The easiest and and safest way to add Python to PATH is by rerunning the installer. -Here is how to do that: - -1. Search for "Apps and features" in the Windows Search Bar. -2. In the "App list" search bar search for "Python": -3. Find the version you want to add to PATH, click the three dots next to the - name, and select "modify". This should open the installer window. -4. Select "Modify", and then click "next" on the "Optional Features" screen. -5. On the "Advanced Options" screen, tick the "Add Python to environment - variables" checkbox: - -  - -6. Click install. - -Python should now be on your PATH! You will need to restart any -terminals/editors you have open before they detect the change. - -### The advanced method: editing environment variables - -If you want more control over the entries in your PATH, you can edit the PATH -environment variables manually. - -### Modifying PATH - -First, to access the PATH variable, search "environment variables" in Windows -search and click on "Edit the system environment variables". Then click the -"Environment Variables" button near the bottom of the window. - -Now there should be two boxes, one for user environment variables and one for -system environment variables. There should be a "Path" entry under both. If you -installed Python for your user account only (the default), double click the -"Path" entry under the "User variables for [username]" section. - -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. - -#### Adding Python to your PATH - -First you will need to find the location of your Python executable. You can find -this by running `py -0p` on the command line and selecting the path you want, or -by adding `import sys;print(sys.executable)` to your code and running that. - -For a standard Python install the file path should look something like -`C:\Users\username\AppData\Local\Programs\Python\Python3xx\python.exe`. To add -this two the path you should add two folders, the one containing `python.exe`, -and the `Scripts/` directory in that directory. In this case the two paths would -be: - -- C:\Users\username\AppData\Local\Programs\Python\Python3xx\ -- C:\Users\username\AppData\Local\Programs\Python\Python3xx\Scripts - -It is important that both paths are added, otherwise `pip` and other commands -will not work correctly. - -To add the paths, click "Add New", and enter the folder name. You can then move -it up above any other Python versions you have installed if necessary. Watch out -for `C:\Users\username\AppData\Local\Microsoft\WindowsApps` as if you have Python -from the Microsoft Store it will be installed there. - -#### Verifying your changes - -You can check that `python` was added to PATH correctly by running -`python -c "import sys;print(sys.executable)"` and checking the executable -returned is the one you want. - -You can check that `pip` was added to PATH correctly by running `pip -V` -and checking the executable matches the one returned by `python` diff --git a/pydis_site/static/images/content/python-on-windows/installer_path_checkbox.png b/pydis_site/static/images/content/python-on-windows/installer_path_checkbox.png Binary files differnew file mode 100644 index 00000000..1091c613 --- /dev/null +++ b/pydis_site/static/images/content/python-on-windows/installer_path_checkbox.png diff --git a/pydis_site/static/images/content/python-on-windows/safe_path_method_1.png b/pydis_site/static/images/content/python-on-windows/safe_path_method_1.png Binary files differnew file mode 100644 index 00000000..0c09c810 --- /dev/null +++ b/pydis_site/static/images/content/python-on-windows/safe_path_method_1.png diff --git a/pydis_site/static/images/content/python-on-windows/safe_path_method_2.png b/pydis_site/static/images/content/python-on-windows/safe_path_method_2.png Binary files differnew file mode 100644 index 00000000..bda60efa --- /dev/null +++ b/pydis_site/static/images/content/python-on-windows/safe_path_method_2.png diff --git a/pydis_site/static/images/content/python-on-windows/safe_path_method_3.png b/pydis_site/static/images/content/python-on-windows/safe_path_method_3.png Binary files differnew file mode 100644 index 00000000..ef438b86 --- /dev/null +++ b/pydis_site/static/images/content/python-on-windows/safe_path_method_3.png diff --git a/pydis_site/static/images/content/python-on-windows/safe_path_method_4.png b/pydis_site/static/images/content/python-on-windows/safe_path_method_4.png Binary files differnew file mode 100644 index 00000000..3cd315d3 --- /dev/null +++ b/pydis_site/static/images/content/python-on-windows/safe_path_method_4.png diff --git a/pydis_site/static/images/content/python-on-windows/safe_path_method_5.png b/pydis_site/static/images/content/python-on-windows/safe_path_method_5.png Binary files differnew file mode 100644 index 00000000..9037bfb1 --- /dev/null +++ b/pydis_site/static/images/content/python-on-windows/safe_path_method_5.png diff --git a/pydis_site/static/images/content/python-on-windows/testing_path_worked_1.png b/pydis_site/static/images/content/python-on-windows/testing_path_worked_1.png Binary files differnew file mode 100644 index 00000000..5d9677e6 --- /dev/null +++ b/pydis_site/static/images/content/python-on-windows/testing_path_worked_1.png diff --git a/pydis_site/static/images/content/python-on-windows/testing_path_worked_2.png b/pydis_site/static/images/content/python-on-windows/testing_path_worked_2.png Binary files differnew file mode 100644 index 00000000..7c71a331 --- /dev/null +++ b/pydis_site/static/images/content/python-on-windows/testing_path_worked_2.png |