From efa1ef32d43ed0f94ff113f6fdd0cc088dc8e39f Mon Sep 17 00:00:00 2001 From: discretegames Date: Sat, 5 Nov 2022 12:52:07 -0700 Subject: Rewrote and added more info to python on ms store article --- .../guides/python-guides/windows/_info.yml | 2 +- .../python-guides/windows/microsoft-store.md | 84 ++++++++++++++------- .../python-on-windows/ms_store_uninstall.png | Bin 0 -> 38764 bytes 3 files changed, 56 insertions(+), 30 deletions(-) create mode 100644 pydis_site/static/images/content/python-on-windows/ms_store_uninstall.png diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/_info.yml b/pydis_site/apps/content/resources/guides/python-guides/windows/_info.yml index 1bb00d29..96c8eb68 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/_info.yml +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/_info.yml @@ -1,2 +1,2 @@ title: Python on Windows -description: Guides related to installing, managing, and troubleshooting Python on Windows +description: Guides related to installing, managing, and troubleshooting Python on Windows operating systems. diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md index 8935163b..daa296de 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md @@ -1,36 +1,62 @@ --- -title: Why not to install Python from the Microsoft Store +title: Why NOT to install Python from the Microsoft Store description: This guide explains the issues with using Python installed from the Microsoft Store --- -Microsoft provides a Python app on the Microsoft Store as an alternative to -using the [Standard Installer](https://www.python.org/downloads/). We would -recommend that you use the standard installer instead wherever possible. +Microsoft provides versions of Python for Windows +[on the Microsoft Store](https://apps.microsoft.com/store/search/python) as an alternative to using the +[full installer from python.org](https://www.python.org/downloads). **We recommend you install Python on Windows using the +[full installer from python.org](https://www.python.org/downloads), +and not from the Microsoft store wherever possible!** + +You can follow [this guide to install Python from python.org](../install-on-windows.md) and more Python Windows releases +can be found [here](https://www.python.org/downloads/windows). Here are some common issues with using Python from the Microsoft Store: -* ##### Command line tools won't work - Most command line tools, like `black` or `pyinstaller`, won't work directly - (without specifying the full path, or invoking them as a module if they allow - it). This happens because they work by adding an executable to the `Scripts/` directory, - which isn't added to PATH on the Microsoft Store version of Python. - -* ##### It can cause issues with permissions - Some modules and scripts wont work with it because of restricted permissions. - This is explained - [in the Python documentation](https://docs.python.org/3/using/windows.html#redirection-of-local-data-registry-and-temporary-paths) - -* ##### It uses PATH inconsistently - `python.exe` isn't added to PATH, but `pip.exe` is. This makes it easy to have - an inconsistent `pip` and `python`. The `pip` is under the - `C:\Users\username\AppData\Local\Microsoft\WindowsApps` entry, which wouldn't - obviously have anything Python related in it. If you add your normal Python - install path below this one, it's `pip` will be overridden by the `WindowsApps` - one but the `python` one wont as it's overwriting the app execution alias. - -* ##### Confusing App Execution Alias Behaviour - The usage of app execution aliases is confusing. If you use the online - installer and for get to tick the box to to add to path, when you try and use - `python`, you either get no output or the Microsoft Store opens. This hides the - command not found error which would have indicated that their install didn't - work as expected. +- ##### Command line tools won't work + + Most command line tools, like [`black`](https://pypi.org/project/black/) or + [`pyinstaller`](https://pypi.org/project/pyinstaller/), won't work directly (without specifying the full path, or + invoking them as a module if they allow it). This happens because they normally work by adding an executable to the + `\Scripts` directory, which isn't added to Path on the Microsoft Store version of Python. + +- ##### It can cause issues with permissions + + Some modules and scripts wont work with it because of restricted permissions. + This is explained + [in the Python documentation](https://docs.python.org/3/using/windows.html#redirection-of-local-data-registry-and-temporary-paths) + +- ##### It can cause Path confusion + + Path is the Windows environment variable that determine what programs run when you type commands in terminals. + (Actually there are two Paths, a user one and a system one that has precedence, but they get [combined when + used](https://superuser.com/a/878382/935845).) With Python from the Microsoft Store installed, your `python`, `py`, + and `pip` commands may get mixed up with the python.org ones, depending on the order and contents of Path. + + The Path entry for the Microsoft Store is `C:\Users\\AppData\Local\Microsoft\WindowsApps`. The entries for the + full python.org install are commonly `C:\Users\\AppData\Local\Programs\Python\Python311` and + `C:\Users\\AppData\Local\Programs\Python\Python311\Scripts` (for Python 3.11). If for some reason you want + both installed, put the ones you want the commands for higher up in Path. + +- ##### Confusing app execution alias behaviour + + Typing `python` into a terminal when it is not already installed or not properly on Path may open up the Microsoft + Store to the Python app, pushing you to install it and confusingly hiding the command not found error that would + normally happen. + + You can change this behavior by searching "Manage app execution aliases" in the Start menu and toggling off "App + Installer" for python.exe and python3.exe. + +- #### You can't specify or easily see the patch version + + The Microsoft Store Python versions are listed simply like 3.10 rather than 3.10.8 even though it may be 3.10.8 + under the hood. It's uncommon, but if you know you need a different patch version ([aka micro + version](https://peps.python.org/pep-0440/#final-releases)), e.g. 3.10.7, you'll need to [install from + python.org](https://www.python.org/downloads/windows/). + +If you have the Microsoft Store version of Python and want to uninstall it, you can search "uninstall" in the Start menu +to open up the "Apps & features" settings and filter by "python". The Python app that has a console in the icon and +"Python Software Foundation" under the name is the Microsoft Store one (see image below). Click it and hit Uninstall. + +![Which version is which when uninstalling Python](/static/images/content/python-on-windows/ms_store_uninstall.png) diff --git a/pydis_site/static/images/content/python-on-windows/ms_store_uninstall.png b/pydis_site/static/images/content/python-on-windows/ms_store_uninstall.png new file mode 100644 index 00000000..40ee954c Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/ms_store_uninstall.png differ -- cgit v1.2.3 From 952c4a5d5340b0866c7f77fae38a714b75dfd21d Mon Sep 17 00:00:00 2001 From: discretegames Date: Sat, 5 Nov 2022 16:35:25 -0700 Subject: added right aligned drake image and a few tweaks to ms store guide --- .../guides/python-guides/windows/microsoft-store.md | 8 ++++++-- .../content/python-on-windows/ms_store_drake.png | Bin 0 -> 1092683 bytes 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 pydis_site/static/images/content/python-on-windows/ms_store_drake.png diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md index daa296de..9e0aa4df 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md @@ -1,8 +1,10 @@ --- -title: Why NOT to install Python from the Microsoft Store +title: Why not to install Python from the Microsoft Store description: This guide explains the issues with using Python installed from the Microsoft Store --- +[](/static/images/content/python-on-windows/ms_store_drake.png) + Microsoft provides versions of Python for Windows [on the Microsoft Store](https://apps.microsoft.com/store/search/python) as an alternative to using the [full installer from python.org](https://www.python.org/downloads). **We recommend you install Python on Windows using the @@ -39,6 +41,8 @@ Here are some common issues with using Python from the Microsoft Store: `C:\Users\\AppData\Local\Programs\Python\Python311\Scripts` (for Python 3.11). If for some reason you want both installed, put the ones you want the commands for higher up in Path. + You can find the path of the executable for a version of Python by running `import sys; print(sys.executable)` in it. + - ##### Confusing app execution alias behaviour Typing `python` into a terminal when it is not already installed or not properly on Path may open up the Microsoft @@ -46,7 +50,7 @@ Here are some common issues with using Python from the Microsoft Store: normally happen. You can change this behavior by searching "Manage app execution aliases" in the Start menu and toggling off "App - Installer" for python.exe and python3.exe. + Installer" for python.exe (and for python3.exe do do the same for the `python3` command). - #### You can't specify or easily see the patch version diff --git a/pydis_site/static/images/content/python-on-windows/ms_store_drake.png b/pydis_site/static/images/content/python-on-windows/ms_store_drake.png new file mode 100644 index 00000000..7cb59c8f Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/ms_store_drake.png differ -- cgit v1.2.3 From 13779f37ee300e18e2fa1fcbc0758befff4a3c54 Mon Sep 17 00:00:00 2001 From: discretegames Date: Sat, 5 Nov 2022 17:07:24 -0700 Subject: final tweaks to ms store article --- .../guides/python-guides/windows/microsoft-store.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md index 9e0aa4df..6ddf1a00 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md @@ -1,9 +1,10 @@ --- title: Why not to install Python from the Microsoft Store -description: This guide explains the issues with using Python installed from the Microsoft Store +description: The drawbacks of installing the Microsoft Store versions of Python --- -[](/static/images/content/python-on-windows/ms_store_drake.png) +[](/static/images/content/python-on-windows/ms_store_drake.png) Microsoft provides versions of Python for Windows [on the Microsoft Store](https://apps.microsoft.com/store/search/python) as an alternative to using the @@ -52,12 +53,16 @@ Here are some common issues with using Python from the Microsoft Store: You can change this behavior by searching "Manage app execution aliases" in the Start menu and toggling off "App Installer" for python.exe (and for python3.exe do do the same for the `python3` command). -- #### You can't specify or easily see the patch version +- #### You can only get certain versions - The Microsoft Store Python versions are listed simply like 3.10 rather than 3.10.8 even though it may be 3.10.8 - under the hood. It's uncommon, but if you know you need a different patch version ([aka micro - version](https://peps.python.org/pep-0440/#final-releases)), e.g. 3.10.7, you'll need to [install from - python.org](https://www.python.org/downloads/windows/). + The Microsoft Store Python versions are listed simply like 3.10 rather than 3.10.8 (though it may be 3.10.8 + under the hood). If you know you need a different [micro version](https://peps.python.org/pep-0440/#final-releases), + e.g. 3.10.7, you'll need to [install from python.org](https://www.python.org/downloads/windows/). + + Additionally, Python 3.7 is the earliest version of Python on the Microsoft Store ([and the description mentions it + may be unstable](https://apps.microsoft.com/store/detail/python-37/9NJ46SX7X90P)). Generally you should be using the + latest Python version you can but if you ever need earlier than 3.7 for testing or for working on older code, the + store can't help. If you have the Microsoft Store version of Python and want to uninstall it, you can search "uninstall" in the Start menu to open up the "Apps & features" settings and filter by "python". The Python app that has a console in the icon and -- cgit v1.2.3 From 3668202153652244adeb356f0201bf155b87205b Mon Sep 17 00:00:00 2001 From: discretegames Date: Sat, 5 Nov 2022 17:09:15 -0700 Subject: Redid windows guide titles/slugs/descriptions to be consistent with planned changes and have nice order --- .../guides/python-guides/windows/common-issues.md | 188 +++++++++++++++++++++ .../python-guides/windows/common-windows-issues.md | 188 --------------------- .../windows/creating-python-environment-windows.md | 60 ------- .../python-guides/windows/install-on-windows.md | 63 ------- .../python-guides/windows/installing-python.md | 67 ++++++++ .../windows/putting-python-on-path.md | 6 + .../guides/python-guides/windows/py-launcher.md | 150 ++++++++++++++++ .../python-guides/windows/python-on-windows.md | 142 ---------------- .../python-guides/windows/unix-env-on-windows.md | 71 ++++++++ 9 files changed, 482 insertions(+), 453 deletions(-) create mode 100644 pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md delete mode 100644 pydis_site/apps/content/resources/guides/python-guides/windows/common-windows-issues.md delete mode 100644 pydis_site/apps/content/resources/guides/python-guides/windows/creating-python-environment-windows.md delete mode 100644 pydis_site/apps/content/resources/guides/python-guides/windows/install-on-windows.md create mode 100644 pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md create mode 100644 pydis_site/apps/content/resources/guides/python-guides/windows/putting-python-on-path.md create mode 100644 pydis_site/apps/content/resources/guides/python-guides/windows/py-launcher.md delete mode 100644 pydis_site/apps/content/resources/guides/python-guides/windows/python-on-windows.md create mode 100644 pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md new file mode 100644 index 00000000..9a09319a --- /dev/null +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -0,0 +1,188 @@ +--- +title: Common issues using Python on Windows +description: A list of common issues with Python on Windows and how to fix them +--- + +TODO!!! rewrite/rearrange in list form with lots of links to other resources + +### When I run `python` in the terminal I get no result, or the Windows Store opens! + +By default Windows has an alias for `python` in the terminal to guide you to +install it from the Microsoft Store. I would not recommend that you install +Python from the Microsoft Store, see why [here](../microsoft-store.md). +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 below question. + +### When I try and run my code with `python` in the terminal I get an error saying the command was not recognised + +If you have not installed Python, you will need to do that. Follow our guide [here](../install-on-windows.md). + +If you have installed python and are still having the issue, it is likely that +you forgot to add to PATH when doing so. See [our guide on adding Python to +PATH](../python-on-windows.md#changing-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](../python-on-windows.md#the-py-launcher) for more information +on that. + +### I `pip` installed a package but when running my code get a `ModuleNotFoundError` + +- #### Are you actually getting a `ModuleNotFoundError`? + + If you are using a code editor such as VSCode or Pycharm you may get a + squiggly line under your import saying the module couldn't be found, it is + possible that this is just an mistake by the editor, so try actually running + your code with to ensure if it actually errors. + + If your code runs fine, you could try restarting your editor. If you have + newly installed a module it may just not have detected it yet. If that + doesn't help, you may need to configure your editor to ensure it is looking + for the module in the correct Python environment. See + [our guide on virtual environments](./python-on-windows.md#virtual-environments) + for more information. + +- #### Was the install successful? + + Look out for errors when installing the module you want. If you get an + error, that's probably why the import isn't working, so you should look + into it. Often a google search will help with this. + +- #### Did you use the correct module name? + + Double check that you haven't made a typo in the name you are importing, or + in what you installed from PyPI, you need to make sure you type the name + exactly as it should be. + + Also, **the name you should `import` may not be the same as the name you `pip install`**. Check the module's documentation or PyPI page if you are unsure. + Examples of this are: + + - [**opencv-python**](https://pypi.org/project/opencv-python/): You need to + `pip install opencv-python`, but the import has to be `import cv2` + - [**discord.py**](https://pypi.org/project/discord.py/): You need to `pip install discord.py`, but the import has to be `import discord` + - [**python-dotenv**](https://pypi.org/project/python-dotenv/): You need to + `pip install python-dotenv`, but the import has to be `import dotenv` + +- #### Are you installing to the same environment you're running your code from? + + This is a very common issue. When you install a module from PyPI, you will + install it into a single Python environment, the one that the `pip` you + invoked is part of. This could be different to the one you are running + the script from if it's using a different Python installation, + or a virtual environment. + + ###### I'm using Pycharm + + PyCharm creates a virtual environment for each project by default, so if + you're installing a module using Pycharm you need to make sure you also run + your code through PyCharm. This also applies the other way round, if you + want to use a module in PyCharm you need to install it through PyCharm. + + It's also possible to change PyCharm to use your system environment, see + [their guide on configuring your interpreter](https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html) + for more information. + + ###### I installed the module using pip from the command line + + Run `pip -V` and look at the path returned it should be in the form + `\Lib\site-packages\pip`. + + Then put `import sys;print(sys.executable);sys.exit(0)` at the top + (above imports!) of your python file, and run it. The result should be + in the form `\python.exe`. + + Now compare that `PATH_TO_PYTHON` to the one from `pip -V`. If they're + different, this is the cause of the `ModuleNotFoundError`. Follow the + relevant "I'm running my code with ..." section below for how to fix + this. + + ###### I'm running my code with `python` from the terminal. + + If you are using a virtual environment, ensure you have activated it before + running `pip install`. You can test this by running `pip -V` and checking + the path is the one of your virtual environment. + + Alternatively, you can use the `py` command to specify the python version + you want to pip install into, e.g. `py -3.9 -m pip install numpy`, and to + specify the executable you want to run your code with, e.g. `py -3.9 + my_script.py`. + + If your `pip` and `python` commands are referring to different python + environments at the same time, it's possible your PATH is configured + incorrectly. See our + [guide for adding Python to PATH](../python-on-windows.md#adding-python-to-your-path) + for how to fix this. + + ###### I'm running my code with the button in VSCode + + To run your code from the same environment you installed Python to, set + the interpreter to the one at the path you found when running `pip -V` + by following + [this guide](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment). + The path should be in the form `PATH_TO_PYTHON\python.exe` + + Alternatively, you can pip install to the currently activated + environment. If you have configured VSCode to use a virtual environment, + it should automatically activate it when you open a new terminal, so + running the `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 recognised + +You pip installed a command line program like `PyInstaller` or `black` that is +intended to be run from the command line, but it does not work. Two common causes +for this are: + +- You are using Python from the Microsoft Store + + To check if this is the case, type `pip -V`. If the path output includes + something like + `PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0`, you + are using Python from the Microsoft Store. To fix this you will either have + to use the full path to the scripts you want to use, or uninstall the + Microsoft Store Python and install Python properly with the online + installer. + +- You manually modified your PATH Environment Variable incorrectly + + If you added `Python` to PATH manually through environment variables, it is + possible that you only added the executable but not the `/Scripts` folder. + This would cause issues with `pip` and make command line tools not + accessible. Look at our [guide on adding Python to the + PATH](../python-on-windows.md#adding-python-to-your-path) for how to verify + and fix this. + +Projects that add a command line program usually work by adding an executable to +the `/Scripts` folder of your Python install. If you clicked "Add to PATH" when +installing Python this folder will have been added to PATH, so anything there +should be runnable directly from the command line. This should also be the case +when using a virtual environment, as long as it is properly activated. + +### 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 loop). This lets you run `Python` code line by line without +having to create a file. + +General commands like `pip` and `python` should be run in the terminal, not in +the Python REPL. To exit the REPL, type `exit()` and press enter. You should +then be able to run your commands normally. + +### I tried to uninstall Python by deleting the folder, now it doesn't work and I can't reinstall it! + +You should never uninstall your Python installation by deleting the folder it is +in. If you have, you may need to edit Registry Keys to fully remove the +installation. Doing this is dangerous and beyond the scope of this guide. + +To uninstall Python properly, run the installer for the version you want to +uninstall and select "uninstall". If you no longer have the installer, you can +re-download it first. diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-windows-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-windows-issues.md deleted file mode 100644 index 0bdb11ef..00000000 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-windows-issues.md +++ /dev/null @@ -1,188 +0,0 @@ ---- -title: Common issues using Python on Windows -description: This guide describes common issues you may run into when using Python on Windows and how to fix them. ---- - -### When I run `python` in the terminal I get no result, or the Windows Store opens! - -By default Windows has an alias for `python` in the terminal to guide you to -install it from the Microsoft Store. I would not recommend that you install -Python from the Microsoft Store, see why [here](../microsoft-store.md). -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 below question. - -### When I try and run my code with `python` in the terminal I get an error saying the command was not recognised - -If you have not installed Python, you will need to do that. Follow our guide [here](../install-on-windows.md). - -If you have installed python and are still having the issue, it is likely that -you forgot to add to PATH when doing so. See [our guide on adding Python to -PATH](../python-on-windows.md#changing-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](../python-on-windows.md#the-py-launcher) for more information -on that. - -### I `pip` installed a package but when running my code get a `ModuleNotFoundError` - -* #### Are you actually getting a `ModuleNotFoundError`? - - If you are using a code editor such as VSCode or Pycharm you may get a - squiggly line under your import saying the module couldn't be found, it is - possible that this is just an mistake by the editor, so try actually running - your code with to ensure if it actually errors. - - If your code runs fine, you could try restarting your editor. If you have - newly installed a module it may just not have detected it yet. If that - doesn't help, you may need to configure your editor to ensure it is looking - for the module in the correct Python environment. See - [our guide on virtual environments](./python-on-windows.md#virtual-environments) - for more information. - -* #### Was the install successful? - - Look out for errors when installing the module you want. If you get an - error, that's probably why the import isn't working, so you should look - into it. Often a google search will help with this. - -* #### Did you use the correct module name? - - Double check that you haven't made a typo in the name you are importing, or - in what you installed from PyPI, you need to make sure you type the name - exactly as it should be. - - Also, **the name you should `import` may not be the same as the name you `pip - install`**. Check the module's documentation or PyPI page if you are unsure. - Examples of this are: - - * [**opencv-python**](https://pypi.org/project/opencv-python/): You need to - `pip install opencv-python`, but the import has to be `import cv2` - * [**discord.py**](https://pypi.org/project/discord.py/): You need to `pip - install discord.py`, but the import has to be `import discord` - * [**python-dotenv**](https://pypi.org/project/python-dotenv/): You need to - `pip install python-dotenv`, but the import has to be `import dotenv` - -* #### Are you installing to the same environment you're running your code from? - - This is a very common issue. When you install a module from PyPI, you will - install it into a single Python environment, the one that the `pip` you - invoked is part of. This could be different to the one you are running - the script from if it's using a different Python installation, - or a virtual environment. - - ###### I'm using Pycharm - - PyCharm creates a virtual environment for each project by default, so if - you're installing a module using Pycharm you need to make sure you also run - your code through PyCharm. This also applies the other way round, if you - want to use a module in PyCharm you need to install it through PyCharm. - - It's also possible to change PyCharm to use your system environment, see - [their guide on configuring your interpreter](https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html) - for more information. - - ###### I installed the module using pip from the command line - - Run `pip -V` and look at the path returned it should be in the form - `\Lib\site-packages\pip`. - - Then put `import sys;print(sys.executable);sys.exit(0)` at the top - (above imports!) of your python file, and run it. The result should be - in the form `\python.exe`. - - Now compare that `PATH_TO_PYTHON` to the one from `pip -V`. If they're - different, this is the cause of the `ModuleNotFoundError`. Follow the - relevant "I'm running my code with ..." section below for how to fix - this. - - ###### I'm running my code with `python` from the terminal. - - If you are using a virtual environment, ensure you have activated it before - running `pip install`. You can test this by running `pip -V` and checking - the path is the one of your virtual environment. - - Alternatively, you can use the `py` command to specify the python version - you want to pip install into, e.g. `py -3.9 -m pip install numpy`, and to - specify the executable you want to run your code with, e.g. `py -3.9 - my_script.py`. - - If your `pip` and `python` commands are referring to different python - environments at the same time, it's possible your PATH is configured - incorrectly. See our - [guide for adding Python to PATH](../python-on-windows.md#adding-python-to-your-path) - for how to fix this. - - ###### I'm running my code with the button in VSCode - - To run your code from the same environment you installed Python to, set - the interpreter to the one at the path you found when running `pip -V` - by following - [this guide](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment). - The path should be in the form `PATH_TO_PYTHON\python.exe` - - Alternatively, you can pip install to the currently activated - environment. If you have configured VSCode to use a virtual environment, - it should automatically activate it when you open a new terminal, so - running the `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 recognised - -You pip installed a command line program like `PyInstaller` or `black` that is -intended to be run from the command line, but it does not work. Two common causes -for this are: - -* You are using Python from the Microsoft Store - - To check if this is the case, type `pip -V`. If the path output includes - something like - `PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0`, you - are using Python from the Microsoft Store. To fix this you will either have - to use the full path to the scripts you want to use, or uninstall the - Microsoft Store Python and install Python properly with the online - installer. - -* You manually modified your PATH Environment Variable incorrectly - - If you added `Python` to PATH manually through environment variables, it is - possible that you only added the executable but not the `/Scripts` folder. - This would cause issues with `pip` and make command line tools not - accessible. Look at our [guide on adding Python to the - PATH](../python-on-windows.md#adding-python-to-your-path) for how to verify - and fix this. - -Projects that add a command line program usually work by adding an executable to -the `/Scripts` folder of your Python install. If you clicked "Add to PATH" when -installing Python this folder will have been added to PATH, so anything there -should be runnable directly from the command line. This should also be the case -when using a virtual environment, as long as it is properly activated. - -### 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 loop). This lets you run `Python` code line by line without -having to create a file. - -General commands like `pip` and `python` should be run in the terminal, not in -the Python REPL. To exit the REPL, type `exit()` and press enter. You should -then be able to run your commands normally. - -### I tried to uninstall Python by deleting the folder, now it doesn't work and I can't reinstall it! - -You should never uninstall your Python installation by deleting the folder it is -in. If you have, you may need to edit Registry Keys to fully remove the -installation. Doing this is dangerous and beyond the scope of this guide. - -To uninstall Python properly, run the installer for the version you want to -uninstall and select "uninstall". If you no longer have the installer, you can -re-download it first. diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/creating-python-environment-windows.md b/pydis_site/apps/content/resources/guides/python-guides/windows/creating-python-environment-windows.md deleted file mode 100644 index 1c654cad..00000000 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/creating-python-environment-windows.md +++ /dev/null @@ -1,60 +0,0 @@ ---- -title: Creating a Unix-style Python Environment on Windows -description: How to setup a Unix style Python Environment ready to start coding in ---- - -Many programmers use Linux or macOS operating systems for their work, though newcomers to programming will likely want to get started on the computer they already own, which will often be running Windows. - -Programmers need to become comfortable using a command prompt (also known as a terminal), and many guides for both beginning and advanced programming will often tell you certain commands to run. -The Windows command prompt has different names for similar commands that are available on Linux and macOS. -This guide will also help you set up a command prompt called Git Bash, which will support many of the commands available on Linux and macOS. - -## Installing Python -First you'll need to install Python. We recommend installing from the Python website, you can follow our guide on how to do this [here](../install-on-windows.md). - -## Installing a text editor -You will also need a text editor for writing Python programs, and for subsequent steps of this guide. -Powerful programs called integrated development environments (IDEs) like PyCharm and Visual Studio Code contain text editors, but they also contain many other features with uses that aren't immediately obvious to new programmers. - -[Notepad++](https://notepad-plus-plus.org/) is a popular text editor for both beginners and advanced users who prefer a simpler interface. -Other editors we recommend can be found [here](https://pythondiscord.com/resources/tools/#editors). - -## Installing Git Bash -Git is a command line program that helps you keep track of changes to your code, among other things. -Many developers use it, and while you may not need it right away, it is useful to install it because it comes with Git Bash. -On the "Select Components" screen, no settings need to be changed. -The next screen will ask what text editor you want to use with Git. Vim is the default choice, though Vim is widely considered difficult to learn, so you may choose to select Notepad++ or whichever text editor you may have installed previously. - -For all remaining screens in the installation, the default selections are fine. - -## Configuring .bashrc -`.bashrc` is a file where we tell Git Bash where the Python executable is. -First, open Git Bash, and as your first command, type `echo ~` and hit enter. -This will most likely print `c/Users/YourUsername` to the terminal. -Navigate to this location in your file explorer, though keep in mind that Windows will display `c/Users/YourUsername` as `C:\Users\YourUsername`. -In this folder, there will be a file called `.bashrc`; open it with your text editor of choice. - -For this step, you will need to remember where you installed Python earlier. -In whichever folder that was, there is a file called `python.exe`; this is the executable that will run your Python programs. -Copy the full path of this file, starting from `C:`. -If you used the example location given earlier, it will be located at `C:\Python\python.exe`. - -In the `.bashrc` file, add a line to the end of the file saying `alias python='C:\\Python\\python.exe`, where `C:\\Python\\python.exe` is the location of your `python.exe` file, but each folder is separated by two backslashes instead of one. -The two backslashes are because a single backslash is used as an [escape character](https://en.wikipedia.org/wiki/Escape_character). -Save the file, and then type `source ~/.bashrc` to activate the change you have made. - -Finally, enter `python -c 'import sys; print(sys.executable)'` into Git Bash. -(If you attempt to copy and paste this into the terminal using Ctrl+V, it might not work, though Shift+Insert will.) -If all the steps have been followed correctly, this will print the location of your `python.exe` file and demonstrate that your environment is set up correctly. -You can hereafter use the `python` command in Git Bash to run any Python program that you write. - -## Running a test program -At any location on your computer, create a file named `hello.py` and open it with your text editor. -The program need only be one line: `print('Hello world!')`. -Save this file. - -To run this program in Git Bash, navigate to where it is saved on your hard drive. -If you know the path to this location, you can use the `cd` command ("cd" stands for "change directory") to navigate to it. -If it's saved to your desktop, `cd /c/Users/YourUsername/Desktop` will take you there. -Otherwise if you have the directory open in your file explorer, you can right click anywhere in the white space of the file explorer window (not on top of a file) and select "Git Bash Here". -Once you're there, type `python hello.py`, and the program will run. diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/install-on-windows.md b/pydis_site/apps/content/resources/guides/python-guides/windows/install-on-windows.md deleted file mode 100644 index 2422e024..00000000 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/install-on-windows.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: Installing Python on Windows -description: How to properly install python on windows ---- - -The recommended way to install Python on windows is directly from the -[Python website's Downloads page](https://www.python.org/downloads/windows/). -Installing Python from the Microsoft Store is not recommended as it can -[cause issues](../microsoft-store.md). - -## Selecting an Installer -There are many different installer options available from the downloads page. -You should usually select the "Windows installer" option instead of the "Windows -embeddable package". Some minor versions may not - -### Which version? -Current Python versions follow the form `3.major.minor`. Major releases happen -yearly and provide new features and breaking changes, whilst minor releases are -more common and only include bug/security fixes. - -Installing the latest major version will give you access to Python's newest -features. However, some modules may not support the newest versions straight -away, so installing the second latest will help you avoid those issues. If you -find you want some newer features or your module does not support your current -version, you can always install another version as well. - -You should generally always install the newest minor version, although some may -not provide an installer in which case you should find the newest that does. - -### 32-bit vs 64-bit? -Install 64-bit python unless you have reason not to. With 32 bit you may run -into memory limits if doing intensive operations (Python will be limited to -using 4GB of memory), and some installed modules may not offer prebuilt wheels -for 32 bit, potentially making installs slower or meaning you have to install -build dependencies. - -If you get an error when installing 64-bit Python, your computer may not support -it. To find out if this is the case, search "About your PC" in windows search -and open the settings page. Then look for the "System Type" option under "Device -Specifications". It should say "64-bit operating system, x64-based processor" if -you have support. You need a 64 bit processor and OS to install 64 bit programs. - -## Running the installer -When you run the installer you should see a screen like this: - -![python_installer_screen](https://user-images.githubusercontent.com/22353562/126144479-cfe6bd98-6d2e-47c3-b6b3-5de9f2656e9a.png) - -Make sure you tick "Add Python 3.x to Path". This allows you to use the `python` -and `pip` commands in your terminal to invoke Python. If you already have a -Python installation on your PATH and don't want this one to override it, don't -tick this. - -If you installed Python without adding to PATH and now want to add it, see -[our guide on adding Python to PATH](../python-on-windows.md#adding-python-to-your-path). - -Then simply click install, and wait for the install to finish! - -To test your installation, type "cmd" in the windows search bar and select -"Command Prompt" to open a terminal (make sure it's opened *after* installation -has finished) type `python -V`, and press enter. If it outputs your python -version, you've successfully installed Python. (if you didn't add to PATH, you -can use [the py launcher](../python-on-windows.md#the-py-launcher) to test -instead). diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md new file mode 100644 index 00000000..09c82865 --- /dev/null +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md @@ -0,0 +1,67 @@ +--- +title: Installing Python on Windows +description: How we recommend installing Python on Windows +--- + +The recommended way to install Python on windows is directly from the +[Python website's Downloads page](https://www.python.org/downloads/windows/). +Installing Python from the Microsoft Store is not recommended as it can +[cause issues](../microsoft-store.md). + +## Selecting an Installer + +There are many different installer options available from the downloads page. +You should usually select the "Windows installer" option instead of the "Windows +embeddable package". Some minor versions may not + +### Which version? + +Current Python versions follow the form `3.minor.micro`. Major releases happen +yearly and provide new features and breaking changes, whilst minor releases are +more common and only include bug/security fixes. + +Installing the latest major version will give you access to Python's newest +features. However, some modules may not support the newest versions straight +away, so installing the second latest will help you avoid those issues. If you +find you want some newer features or your module does not support your current +version, you can always install another version as well. + +You should generally always install the newest minor version, although some may +not provide an installer in which case you should find the newest that does. + +### 32-bit vs 64-bit? + +Install 64-bit python unless you have reason not to. With 32 bit you may run +into memory limits if doing intensive operations (Python will be limited to +using 4GB of memory), and some installed modules may not offer prebuilt wheels +for 32 bit, potentially making installs slower or meaning you have to install +build dependencies. + +If you get an error when installing 64-bit Python, your computer may not support +it. To find out if this is the case, search "About your PC" in windows search +and open the settings page. Then look for the "System Type" option under "Device +Specifications". It should say "64-bit operating system, x64-based processor" if +you have support. You need a 64 bit processor and OS to install 64 bit programs. + +## Running the installer + +When you run the installer you should see a screen like this: + +![python_installer_screen](https://user-images.githubusercontent.com/22353562/126144479-cfe6bd98-6d2e-47c3-b6b3-5de9f2656e9a.png) + +Make sure you tick "Add Python 3.x to Path". This allows you to use the `python` +and `pip` commands in your terminal to invoke Python. If you already have a +Python installation on your PATH and don't want this one to override it, don't +tick this. + +If you installed Python without adding to PATH and now want to add it, see +[our guide on adding Python to PATH](../python-on-windows.md#adding-python-to-your-path). + +Then simply click install, and wait for the install to finish! + +To test your installation, type "cmd" in the windows search bar and select +"Command Prompt" to open a terminal (make sure it's opened _after_ installation +has finished) type `python -V`, and press enter. If it outputs your python +version, you've successfully installed Python. (if you didn't add to PATH, you +can use [the py launcher](../python-on-windows.md#the-py-launcher) to test +instead). 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 new file mode 100644 index 00000000..25bf8d8f --- /dev/null +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/putting-python-on-path.md @@ -0,0 +1,6 @@ +--- +title: Putting Python on Path +description: How to make sure Python is properly on the Windows Path environment variable +--- + +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 new file mode 100644 index 00000000..416d13ec --- /dev/null +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/py-launcher.md @@ -0,0 +1,150 @@ +--- +title: The py Launcher on Windows +description: Common commands and usage of the 'py' Python launcher +--- + +TODO!!! rewrite/rearrange to be all about the py command + +## The py launcher + +By default, Python installed on Windows using the online Python installer comes +with the "py launcher". It is a command line tool you invoke using the `py` +command, and helps you invoke a specific python version. + +It provides the `py -0p` command. This lists the python versions you have +installed, the output will look like this: + + C:\Users\username>py -0p + Installed Pythons found by py Launcher for Windows + -V:3.11 C:\Users\username\AppData\Local\Programs\Python\Python311\python.exe + -V:3.10 C:\Users\username\AppData\Local\Programs\Python\Python310\python.exe + -V:3.9 * C:\Users\username\AppData\Local\Programs\Python\Python39\python.exe + +The versions will be ordered from newest to oldest, and the `*` will indicate +which version running `py` will call by default. This depends on the following +requirements, and may not be the same version you get from running `python` (if +you get any): + +```text +If an exact version is not given, using the latest version can be overridden by +any of the following, (in priority order): +• An active virtual environment +• A shebang line in the script (if present) +• With -2 or -3 flag a matching PY_PYTHON2 or PY_PYTHON3 Environment variable +• A PY_PYTHON Environment variable +• From [defaults] in py.ini in your %LOCALAPPDATA%\py.ini +• From [defaults] in py.ini beside py.exe (use `where py` to locate) +``` + +You can override which version is called by specifying the major and minor +versions to used. For example, to invoke python 3.7, you could run `py -3.7`. +You can then pass any arguments to `python` on top of that, for example +`py -3.7 myscript.py` to run `myscript.py`, or `py -3.7 -m pip install numpy` +to invoke `pip` to install numpy into that version. + +You can use `py` instead of `python` and not have any python versions on PATH at +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: + + ![NkeEczCt2U](https://user-images.githubusercontent.com/22353562/126303895-60155ea5-7189-4924-9aa7-de696ca02ae9.png) + +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/apps/content/resources/guides/python-guides/windows/python-on-windows.md b/pydis_site/apps/content/resources/guides/python-guides/windows/python-on-windows.md deleted file mode 100644 index 76ca0bc7..00000000 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/python-on-windows.md +++ /dev/null @@ -1,142 +0,0 @@ ---- -title: Python on Windows -description: This guide explains how manage your Python installation(s) on Windows ---- - -## The py launcher -By default, Python installed on Windows using the online Python installer comes -with the "py launcher". It is a command line tool you invoke using the `py` -command, and helps you invoke a specific python version. - -It provides the `py -0p` command. This lists the python versions you have -installed, the output will look like this: - - C:\Users\username>py -0p - Installed Pythons found by py Launcher for Windows - -V:3.11 C:\Users\username\AppData\Local\Programs\Python\Python311\python.exe - -V:3.10 C:\Users\username\AppData\Local\Programs\Python\Python310\python.exe - -V:3.9 * C:\Users\username\AppData\Local\Programs\Python\Python39\python.exe - -The versions will be ordered from newest to oldest, and the `*` will indicate -which version running `py` will call by default. This depends on the following -requirements, and may not be the same version you get from running `python` (if -you get any): -```text -If an exact version is not given, using the latest version can be overridden by -any of the following, (in priority order): -• An active virtual environment -• A shebang line in the script (if present) -• With -2 or -3 flag a matching PY_PYTHON2 or PY_PYTHON3 Environment variable -• A PY_PYTHON Environment variable -• From [defaults] in py.ini in your %LOCALAPPDATA%\py.ini -• From [defaults] in py.ini beside py.exe (use `where py` to locate) -``` -You can override which version is called by specifying the major and minor -versions to used. For example, to invoke python 3.7, you could run `py -3.7`. -You can then pass any arguments to `python` on top of that, for example -`py -3.7 myscript.py` to run `myscript.py`, or `py -3.7 -m pip install numpy` -to invoke `pip` to install numpy into that version. - -You can use `py` instead of `python` and not have any python versions on PATH at -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: - - ![NkeEczCt2U](https://user-images.githubusercontent.com/22353562/126303895-60155ea5-7189-4924-9aa7-de696ca02ae9.png) - -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/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md b/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md new file mode 100644 index 00000000..28322f7c --- /dev/null +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md @@ -0,0 +1,71 @@ +--- +title: Setting up a Unix-style Python Environment on Windows +description: How to setup a Unix-style Python environment ready to start coding in +--- + + + +Many programmers use Linux or macOS operating systems for their work, though newcomers to programming will likely want +to get started on the computer they already own, which will often be running Windows. + +Programmers need to become comfortable using a command prompt (also known as a terminal or shell), and many guides for +both beginning and advanced programming will often tell you certain commands to run. The Windows command prompt has +different names for similar commands that are available on Linux and macOS. This guide will also help you set up a +command prompt called Git Bash, which will support many of the commands available on Linux and macOS. + +## Installing Python + +First you'll need to install Python. We recommend installing from the Python website, you can follow our guide on how to +do this [here](../install-on-windows.md). + +## Installing a text editor + +You will also need a text editor for writing Python programs, and for subsequent steps of this guide. Powerful programs +called integrated development environments (IDEs) like PyCharm and Visual Studio Code contain text editors, but they +also contain many other features with uses that aren't immediately obvious to new programmers. + +[Notepad++](https://notepad-plus-plus.org/) is a popular text editor for both beginners and advanced users who prefer a +simpler interface. Other editors we recommend can be found [here](https://pythondiscord.com/resources/tools/#editors). + +## Installing Git Bash + +Git is a command line program that helps you keep track of changes to your code, among other things. Many developers use +it, and while you may not need it right away, it is useful to install it because it comes with Git Bash. On the "Select +Components" screen, no settings need to be changed. The next screen will ask what text editor you want to use with Git. +Vim is the default choice, though Vim is widely considered difficult to learn, so you may choose to select Notepad++ or +whichever text editor you may have installed previously. + +For all remaining screens in the installation, the default selections are fine. + +## Configuring .bashrc + +`.bashrc` is a file where we tell Git Bash where the Python executable is. First, open Git Bash, and as your first +command, type `echo ~` and hit enter. This will most likely print `c/Users/YourUsername` to the terminal. Navigate to +this location in your file explorer, though keep in mind that Windows will display `c/Users/YourUsername` as +`C:\Users\YourUsername`. In this folder, there will be a file called `.bashrc`; open it with your text editor of choice. + +For this step, you will need to remember where you installed Python earlier. In whichever folder that was, there is a +file called `python.exe`; this is the executable that will run your Python programs. Copy the full path of this file, +starting from `C:`. If you used the example location given earlier, it will be located at `C:\Python\python.exe`. + +In the `.bashrc` file, add a line to the end of the file saying `alias python='C:\\Python\\python.exe`, where +`C:\\Python\\python.exe` is the location of your `python.exe` file, but each folder is separated by two backslashes +instead of one. The two backslashes are because a single backslash is used as an [escape +character](https://en.wikipedia.org/wiki/Escape_character). Save the file, and then type `source ~/.bashrc` to activate +the change you have made. + +Finally, enter `python -c 'import sys; print(sys.executable)'` into Git Bash. (If you attempt to copy and paste this +into the terminal using Ctrl+V, it might not work, though Shift+Insert will.) If all the steps have been followed +correctly, this will print the location of your `python.exe` file and demonstrate that your environment is set up +correctly. You can hereafter use the `python` command in Git Bash to run any Python program that you write. + +## Running a test program + +At any location on your computer, create a file named `hello.py` and open it with your text editor. The program need +only be one line: `print('Hello world!')`. Save this file. + +To run this program in Git Bash, navigate to where it is saved on your hard drive. If you know the path to this +location, you can use the `cd` command ("cd" stands for "change directory") to navigate to it. If it's saved to your +desktop, `cd /c/Users/YourUsername/Desktop` will take you there. Otherwise if you have the directory open in your file +explorer, you can right click anywhere in the white space of the file explorer window (not on top of a file) and select +"Git Bash Here". Once you're there, type `python hello.py`, and the program will run. -- cgit v1.2.3 From 19caa0afe9a9e5e0fd2c22e1ca8dfbc4ae659de2 Mon Sep 17 00:00:00 2001 From: discretegames Date: Sun, 6 Nov 2022 15:12:50 -0800 Subject: Rewrote safe method for adding Python to path, in own article --- .../windows/putting-python-on-path.md | 100 ++++++++++++++++++++ .../guides/python-guides/windows/py-launcher.md | 105 +-------------------- .../python-on-windows/installer_path_checkbox.png | Bin 0 -> 88161 bytes .../python-on-windows/safe_path_method_1.png | Bin 0 -> 19187 bytes .../python-on-windows/safe_path_method_2.png | Bin 0 -> 81018 bytes .../python-on-windows/safe_path_method_3.png | Bin 0 -> 86229 bytes .../python-on-windows/safe_path_method_4.png | Bin 0 -> 91467 bytes .../python-on-windows/safe_path_method_5.png | Bin 0 -> 91674 bytes .../python-on-windows/testing_path_worked_1.png | Bin 0 -> 22075 bytes .../python-on-windows/testing_path_worked_2.png | Bin 0 -> 27470 bytes 10 files changed, 103 insertions(+), 102 deletions(-) create mode 100644 pydis_site/static/images/content/python-on-windows/installer_path_checkbox.png create mode 100644 pydis_site/static/images/content/python-on-windows/safe_path_method_1.png create mode 100644 pydis_site/static/images/content/python-on-windows/safe_path_method_2.png create mode 100644 pydis_site/static/images/content/python-on-windows/safe_path_method_3.png create mode 100644 pydis_site/static/images/content/python-on-windows/safe_path_method_4.png create mode 100644 pydis_site/static/images/content/python-on-windows/safe_path_method_5.png create mode 100644 pydis_site/static/images/content/python-on-windows/testing_path_worked_1.png create mode 100644 pydis_site/static/images/content/python-on-windows/testing_path_worked_2.png 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: + +![Add Python to path installer checkbox.](/static/images/content/python-on-windows/installer_path_checkbox.png) + +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. + + ![Step 1](/static/images/content/python-on-windows/safe_path_method_1.png) + +2. Select "Modify". (If you don't see the "Modify/Repair/Uninstall" screen then you likely have the wrong installer.) + + ![Step 2](/static/images/content/python-on-windows/safe_path_method_2.png) + +3. Hit "Next" to move past the "Optional Features" screen. + + ![Step 3](/static/images/content/python-on-windows/safe_path_method_3.png) + +4. Check "Add Python to environment variables" on the "Advanced Options" screen. + + ![Step 4](/static/images/content/python-on-windows/safe_path_method_4.png) + +5. Hit install! + + ![Step 5](/static/images/content/python-on-windows/safe_path_method_5.png) + +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: + +![Checking Python and pip versions.](/static/images/content/python-on-windows/testing_path_worked_1.png) + +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: + +![Checking Python executable.](/static/images/content/python-on-windows/testing_path_worked_2.png) + +(Type `exit()` from here to go back to the normal terminal.) + + + +Of course your username will probably not be "r" like mine is, and your executable path may differ from +`C:\Users\\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: - - ![NkeEczCt2U](https://user-images.githubusercontent.com/22353562/126303895-60155ea5-7189-4924-9aa7-de696ca02ae9.png) - -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 new file mode 100644 index 00000000..1091c613 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/installer_path_checkbox.png differ 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 new file mode 100644 index 00000000..0c09c810 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/safe_path_method_1.png differ 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 new file mode 100644 index 00000000..bda60efa Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/safe_path_method_2.png differ 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 new file mode 100644 index 00000000..ef438b86 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/safe_path_method_3.png differ 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 new file mode 100644 index 00000000..3cd315d3 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/safe_path_method_4.png differ 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 new file mode 100644 index 00000000..9037bfb1 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/safe_path_method_5.png differ 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 new file mode 100644 index 00000000..5d9677e6 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/testing_path_worked_1.png differ 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 new file mode 100644 index 00000000..7c71a331 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/testing_path_worked_2.png differ -- cgit v1.2.3 From 40ad001c24c2f74438f4f35036f0883c8325943d Mon Sep 17 00:00:00 2001 From: discretegames Date: Sun, 6 Nov 2022 22:04:00 -0800 Subject: finished detailed, screenshot full, putting python on path guide --- .../guides/python-guides/windows/common-issues.md | 1 + .../python-guides/windows/installing-python.md | 1 + .../python-guides/windows/microsoft-store.md | 1 + .../windows/putting-python-on-path.md | 159 +++++++++++++++++++-- .../guides/python-guides/windows/py-launcher.md | 1 + .../python-guides/windows/unix-env-on-windows.md | 1 + .../content/python-on-windows/edit_path_1.png | Bin 0 -> 320453 bytes .../content/python-on-windows/edit_path_2.png | Bin 0 -> 20777 bytes .../content/python-on-windows/edit_path_3.png | Bin 0 -> 43213 bytes .../content/python-on-windows/edit_path_4.png | Bin 0 -> 21217 bytes .../content/python-on-windows/edit_path_5.png | Bin 0 -> 22969 bytes .../content/python-on-windows/edit_path_6.png | Bin 0 -> 28537 bytes .../content/python-on-windows/finding_exe_1.png | Bin 0 -> 18024 bytes .../content/python-on-windows/finding_exe_2.png | Bin 0 -> 8417 bytes .../content/python-on-windows/finding_exe_3.png | Bin 0 -> 64343 bytes .../python-on-windows/system_path_important.png | Bin 0 -> 3169 bytes 16 files changed, 152 insertions(+), 12 deletions(-) create mode 100644 pydis_site/static/images/content/python-on-windows/edit_path_1.png create mode 100644 pydis_site/static/images/content/python-on-windows/edit_path_2.png create mode 100644 pydis_site/static/images/content/python-on-windows/edit_path_3.png create mode 100644 pydis_site/static/images/content/python-on-windows/edit_path_4.png create mode 100644 pydis_site/static/images/content/python-on-windows/edit_path_5.png create mode 100644 pydis_site/static/images/content/python-on-windows/edit_path_6.png create mode 100644 pydis_site/static/images/content/python-on-windows/finding_exe_1.png create mode 100644 pydis_site/static/images/content/python-on-windows/finding_exe_2.png create mode 100644 pydis_site/static/images/content/python-on-windows/finding_exe_3.png create mode 100644 pydis_site/static/images/content/python-on-windows/system_path_important.png diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md index 9a09319a..45fd4331 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -1,6 +1,7 @@ --- title: Common issues using Python on Windows description: A list of common issues with Python on Windows and how to fix them +icon: fab fa-windows --- TODO!!! rewrite/rearrange in list form with lots of links to other resources diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md index 09c82865..e9cf6343 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md @@ -1,6 +1,7 @@ --- title: Installing Python on Windows description: How we recommend installing Python on Windows +icon: fab fa-windows --- The recommended way to install Python on windows is directly from the diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md index 6ddf1a00..e4bac067 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md @@ -1,6 +1,7 @@ --- title: Why not to install Python from the Microsoft Store description: The drawbacks of installing the Microsoft Store versions of Python +icon: fab fa-windows --- [ + 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 @@ -17,7 +21,7 @@ environment variable is improperly configured for Python. This just means Window 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 +you type a command name in your terminal, like `python` or `pip`, the terminal looks for a program of 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, @@ -34,7 +38,8 @@ method](#advanced-method-manually-edit-the-path) that explains how to edit the P 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`). +[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: @@ -58,11 +63,18 @@ Once you have it, here are the steps to modify the installation to add Python to ![Step 5](/static/images/content/python-on-windows/safe_path_method_5.png) -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.** +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.) -(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.) +### Verifying your changes -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 +To check that it worked, open a fresh 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 @@ -88,19 +100,142 @@ to see that the exact executable that is currently running Python is what you ex ![Checking Python executable.](/static/images/content/python-on-windows/testing_path_worked_2.png) -(Type `exit()` from here to go back to the normal terminal.) +Type `exit()` from here to go back to the normal terminal. -Of course your username will probably not be "r" like mine is, and your executable path may differ from +Of course your username will probably not be "r", and your executable path may differ from `C:\Users\\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! +differences don't matter if `python` and `pip` and other things like `pyinstaller` (if you've [pip +installed](https://pypi.org/project/pyinstaller/) 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. +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. (If +you already did that, open a help channel on the [Python Discord server](https://discord.com/invite/python) and someone +will hopefully be able to help.) ## Advanced Method: Manually edit the Path -TODO!!! +As mentioned above, the Path (often called "PATH", though it shows up as "Path") is what Windows uses to locate +executables needed on the command line. If it's misconfigured, `python` and `pip` commands may not work as +expected. + +"Path" is the name of a Windows environment variable whose value is simply a list of paths to folders on the system. A +_path_ is just string that locates a folder, like `C:\Program Files\Git\cmd`. An _environment variable_ is a variable (a +thing with a name and a value) that is available to the entire system, or at least to an entire user of the system. + +In fact, the Windows Path is technically _two_ environment variables, two lists of folders: a System one and a User one. +But, as explained [here](https://superuser.com/a/878382), when actually used, the User Path is appended to the System +Path, forming one long list. + +So, how it works is whenever you type a command like `python` into a terminal, the terminal looks for a matching +runnable file like `python.exe` (or [`python.bat`](https://en.wikipedia.org/wiki/Batch_file)) in each of the folders +listed in the Path, starting with the System Path (top to bottom), and then the User Path (top to bottom). It stops +searching on the first one it finds and runs that program with the command line arguments you may have given it, hence +(hopefully) running Python from an installed `python.exe`. + +If it can't find a runnable file that matches the command name, it spits out an error like: + +```text +foobar: The term 'foobar' is not recognized as the name of a cmdlet, function, script file, or operable program. +``` + +Or, in the case of not finding `python`, it may [open up the Microsoft +store](../microsoft-store.md#confusing-app-execution-alias-behaviour). + +Again, the Path lookup order is: + +> System Path (top to bottom) → User Path (top to bottom) → Command not found error + +### Adding Python to your Path + +Here the common case of adding Python to the Windows Path is detailed. Though knowing how to manually modify the Path is +handy beyond that whenever you need to change or debug which programs run on the command line. (The less customizable +but [safer method is above](#safe-method-let-the-installer-add-python-to-path) if you missed it.) + +Follow these steps to add Python to the Path: + +1. First, find folder path your Python executable is in. There are a couple ways to do this: + + **Way 1**: Run `py -0p` on the command line and copy the folder path of the version you want: + + ![Finding exe with py.](/static/images/content/python-on-windows/finding_exe_1.png) + + **Way 2**: Run `import sys; print(sys.executable)` in Python on your PC and copy the folder path it prints out: + + ![Finding exe in repl.](/static/images/content/python-on-windows/finding_exe_2.png) + + Either way I end up with `C:\Users\r\AppData\Local\Programs\Python\Python311\` (no `python.exe` at the end). + Your path will of course be based on your username (my username is "r") and your version of Python, such as + `C:\Users\ducky\AppData\Local\Programs\Python\Python39\` if your username is "ducky" and you're using Python 3.9. + Copy your path, we'll use it in steps 6 and 7. + +2. [This step is optional but helpful to see what's going on.] Copy the folder path from step 1 into the path bar of + Windows File Explorer. In the folder you should be able to see `python.exe`, and in the Scripts subfolder, things + like `pip.exe` and `pyinstaller.exe` (if you have it installed). + + ![Finding exes in folder.](/static/images/content/python-on-windows/finding_exe_3.png) + + These are the executables we want the command line to be able to find via the Windows Path. + +3. Now, type "environment variables" in the Start menu or Start search box and open the "Edit the system environment + variables" option. + + ![Step 3](/static/images/content/python-on-windows/edit_path_1.png) + +4. Hit the "Environment Variables..." button. + + ![Step 4](/static/images/content/python-on-windows/edit_path_2.png) + +5. In a new window you should see two "Path" variables, one under "User variables for <user>" and one under + "System variables". Select one of them (most likely the User Path) and hit the "Edit..." button underneath it. + + I suggest using the User Path (what the screenshots show) for the default installation of Python. In general, only + put things on the System Path if they are installed for all users (e.g. in `C:\Program Files` or `C:\`) and you're + certain they won't overshadow anything in User Paths. **Remember, the System Path takes precedence over the User + Path when commands are looked up.** + + ![Step 5](/static/images/content/python-on-windows/edit_path_3.png) + + (Don't worry if your variables or Path contents differ a bit from those shown.) + +6. The third window that opens is where the Path is actually edited. It shows the ordered list of the folders on the + Path and you can select the entries, edit them, reorder them, make new ones, delete them and so on. (Don't delete + any unless you know what you're doing!) + + We want to add the Python executable path we found in step 1 as a new entry, so click "New" and paste in the path. + + ![Step 6](/static/images/content/python-on-windows/edit_path_4.png) + +7. We also need to add the Python Scripts directory to the Path to have commands like `pip` and `pyinstaller` work. So + hit "New" and paste in the Python executable path again, and type "Scripts" after it. + + ![Step 7](/static/images/content/python-on-windows/edit_path_5.png) + +8. Finally, select each of the paths you just added in turn and move them to the very top of the list using the "Move + Up" button. (Their relative order should not matter.) + + ![Step 8](/static/images/content/python-on-windows/edit_path_6.png) + + This step may not be strictly necessary, but remember that command lookup happens in order from top to bottom. + Python is often bundled with other software that may end up on the Path, so there's there could be another + `python.exe` in one of of the other folders on the path that gets in the way. (This exact thing has happened to me when + I put `C:\Program Files\Inkscape\bin` on my Path, as [Inkscape](https://inkscape.org/) comes with a copy of Python.) + + Also, the System Path comes first in command lookup, so to be certain you to may want to go back and check the + System Path (see step 5) and _carefully_ delete any entry that is a Python executable path blocking the one you just + added. Though please, don't delete any Path entries you're aren't sure about! Just in case, for reference, [here are + the important looking System Path entries](/static/images/content/python-on-windows/system_path_important.png) on my + Windows 10 64-bit PC. + +9. Finish by making sure to hit "OK" on each of the thee "Edit environment variable", "Environment Variable", and + "System Properties" windows, and then you're done! + + Python and Python Scripts should not be on your Path! **You will need to restart any terminals or editors you have open before they detect the change.** + +At this point you can [verify your changes in the same way as detailed above](#verifying-your-changes). Hopefully it +works! + +(These steps were written with Windows 10 and Python 3.11 in mind, but they should be identical or similar for Windows +11 and other recent versions of Python.) 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 673a1759..388177ec 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,6 +1,7 @@ --- title: The py Launcher on Windows description: Common commands and usage of the Windows "py" Python launcher +icon: fab fa-windows --- When you install Python on Windows fron diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md b/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md index 28322f7c..f52ddfed 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md @@ -1,6 +1,7 @@ --- title: Setting up a Unix-style Python Environment on Windows description: How to setup a Unix-style Python environment ready to start coding in +icon: fab fa-windows --- diff --git a/pydis_site/static/images/content/python-on-windows/edit_path_1.png b/pydis_site/static/images/content/python-on-windows/edit_path_1.png new file mode 100644 index 00000000..bf5d4a66 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/edit_path_1.png differ diff --git a/pydis_site/static/images/content/python-on-windows/edit_path_2.png b/pydis_site/static/images/content/python-on-windows/edit_path_2.png new file mode 100644 index 00000000..99c6eae5 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/edit_path_2.png differ diff --git a/pydis_site/static/images/content/python-on-windows/edit_path_3.png b/pydis_site/static/images/content/python-on-windows/edit_path_3.png new file mode 100644 index 00000000..dbc74a97 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/edit_path_3.png differ diff --git a/pydis_site/static/images/content/python-on-windows/edit_path_4.png b/pydis_site/static/images/content/python-on-windows/edit_path_4.png new file mode 100644 index 00000000..bae5631d Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/edit_path_4.png differ diff --git a/pydis_site/static/images/content/python-on-windows/edit_path_5.png b/pydis_site/static/images/content/python-on-windows/edit_path_5.png new file mode 100644 index 00000000..c0338888 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/edit_path_5.png differ diff --git a/pydis_site/static/images/content/python-on-windows/edit_path_6.png b/pydis_site/static/images/content/python-on-windows/edit_path_6.png new file mode 100644 index 00000000..e01d15bc Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/edit_path_6.png differ diff --git a/pydis_site/static/images/content/python-on-windows/finding_exe_1.png b/pydis_site/static/images/content/python-on-windows/finding_exe_1.png new file mode 100644 index 00000000..6b46bef1 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/finding_exe_1.png differ diff --git a/pydis_site/static/images/content/python-on-windows/finding_exe_2.png b/pydis_site/static/images/content/python-on-windows/finding_exe_2.png new file mode 100644 index 00000000..5c6020ec Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/finding_exe_2.png differ diff --git a/pydis_site/static/images/content/python-on-windows/finding_exe_3.png b/pydis_site/static/images/content/python-on-windows/finding_exe_3.png new file mode 100644 index 00000000..753d17e8 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/finding_exe_3.png differ diff --git a/pydis_site/static/images/content/python-on-windows/system_path_important.png b/pydis_site/static/images/content/python-on-windows/system_path_important.png new file mode 100644 index 00000000..1236cf41 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/system_path_important.png differ -- cgit v1.2.3 From a7c59dd5078dc37a204ebcf979e9cc99d3c6c373 Mon Sep 17 00:00:00 2001 From: discretegames Date: Mon, 7 Nov 2022 15:12:39 -0800 Subject: Proofread, tweaked, added links to common windows issues guide. (Also normalized to 120 wide with rewrap vsc ext) --- .../guides/python-guides/windows/common-issues.md | 265 +++++++++------------ 1 file changed, 119 insertions(+), 146 deletions(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md index 45fd4331..4d8530d5 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -4,186 +4,159 @@ description: A list of common issues with Python on Windows and how to fix them icon: fab fa-windows --- -TODO!!! rewrite/rearrange in list form with lots of links to other resources - ### When I run `python` in the terminal I get no result, or the Windows Store opens! -By default Windows has an alias for `python` in the terminal to guide you to -install it from the Microsoft Store. I would not recommend that you install -Python from the Microsoft Store, see why [here](../microsoft-store.md). -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. +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. +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 below question. +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 recognised +### 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](../install-on-windows.md). +If you have not installed Python, you will need to do that. Follow our guide [here](../installing-python). -If you have installed python and are still having the issue, it is likely that -you forgot to add to PATH when doing so. See [our guide on adding Python to -PATH](../python-on-windows.md#changing-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](../python-on-windows.md#the-py-launcher) for more information -on that. +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](../py-launcher) for more information on that. ### I `pip` installed a package but when running my code get a `ModuleNotFoundError` - #### Are you actually getting a `ModuleNotFoundError`? - If you are using a code editor such as VSCode or Pycharm you may get a - squiggly line under your import saying the module couldn't be found, it is - possible that this is just an mistake by the editor, so try actually running - your code with to ensure if it actually errors. + If you are using a code editor such as VSCode or PyCharm you may get a squiggly line under your import saying the + module couldn't be found, it is possible that this is just an mistake by the editor, so try actually running your + code with to ensure if it actually errors. - If your code runs fine, you could try restarting your editor. If you have - newly installed a module it may just not have detected it yet. If that - doesn't help, you may need to configure your editor to ensure it is looking - for the module in the correct Python environment. See - [our guide on virtual environments](./python-on-windows.md#virtual-environments) - for more information. + If your code runs fine, you could try restarting your editor. If you have newly installed a module it may just not + have detected it yet. If that doesn't help, you may need to configure your editor to ensure it is looking for the + module in the correct Python environment. See [our guide on virtual environments](dg:TODO) for more information. - #### Was the install successful? - Look out for errors when installing the module you want. If you get an - error, that's probably why the import isn't working, so you should look - into it. Often a google search will help with this. + Look out for errors when installing the module you want. If you get an error, that's probably why the import isn't + working, so you should look into it. Often a Google search of the relevant error text will help. - #### Did you use the correct module name? - Double check that you haven't made a typo in the name you are importing, or - in what you installed from PyPI, you need to make sure you type the name - exactly as it should be. - - Also, **the name you should `import` may not be the same as the name you `pip install`**. Check the module's documentation or PyPI page if you are unsure. - Examples of this are: - - - [**opencv-python**](https://pypi.org/project/opencv-python/): You need to - `pip install opencv-python`, but the import has to be `import cv2` - - [**discord.py**](https://pypi.org/project/discord.py/): You need to `pip install discord.py`, but the import has to be `import discord` - - [**python-dotenv**](https://pypi.org/project/python-dotenv/): You need to - `pip install python-dotenv`, but the import has to be `import dotenv` - -- #### Are you installing to the same environment you're running your code from? - - This is a very common issue. When you install a module from PyPI, you will - install it into a single Python environment, the one that the `pip` you - invoked is part of. This could be different to the one you are running - the script from if it's using a different Python installation, - or a virtual environment. - - ###### I'm using Pycharm - - PyCharm creates a virtual environment for each project by default, so if - you're installing a module using Pycharm you need to make sure you also run - your code through PyCharm. This also applies the other way round, if you - want to use a module in PyCharm you need to install it through PyCharm. - - It's also possible to change PyCharm to use your system environment, see - [their guide on configuring your interpreter](https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html) - for more information. - - ###### I installed the module using pip from the command line + Double check that you haven't made a typo in the name you are importing, or in what you installed from + [PyPI](https://pypi.org/), you need to make sure you type the name exactly as it should be. - Run `pip -V` and look at the path returned it should be in the form - `\Lib\site-packages\pip`. + Also, **the name you should `import` may not be the same as the name you `pip install`**. Check the module's + documentation or PyPI page if you are unsure. Examples of this are: - Then put `import sys;print(sys.executable);sys.exit(0)` at the top - (above imports!) of your python file, and run it. The result should be - in the form `\python.exe`. + - [**opencv-python**](https://pypi.org/project/opencv-python/): You need to `pip install opencv-python`, but the + import has to be `import cv2` + - [**discord.py**](https://pypi.org/project/discord.py/): You need to `pip install discord.py`, but the import has + to be `import discord` + - [**python-dotenv**](https://pypi.org/project/python-dotenv/): You need to `pip install python-dotenv`, but the + import has to be `import dotenv` + - [**Pillow**](https://pypi.org/project/Pillow/): You need to `pip install Pillow`, but the import is + usually `from PIL import Image`. - Now compare that `PATH_TO_PYTHON` to the one from `pip -V`. If they're - different, this is the cause of the `ModuleNotFoundError`. Follow the - relevant "I'm running my code with ..." section below for how to fix - this. + Normal imports in Python can't have dashes (`-`) in them as it would be interpreted as subtraction. Though [there + are workarounds](https://stackoverflow.com/questions/7583652/python-module-with-a-dash-or-hyphen-in-its-name). - ###### I'm running my code with `python` from the terminal. - - If you are using a virtual environment, ensure you have activated it before - running `pip install`. You can test this by running `pip -V` and checking - the path is the one of your virtual environment. - - Alternatively, you can use the `py` command to specify the python version - you want to pip install into, e.g. `py -3.9 -m pip install numpy`, and to - specify the executable you want to run your code with, e.g. `py -3.9 - my_script.py`. - - If your `pip` and `python` commands are referring to different python - environments at the same time, it's possible your PATH is configured - incorrectly. See our - [guide for adding Python to PATH](../python-on-windows.md#adding-python-to-your-path) - for how to fix this. - - ###### I'm running my code with the button in VSCode - - To run your code from the same environment you installed Python to, set - the interpreter to the one at the path you found when running `pip -V` - by following - [this guide](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment). - The path should be in the form `PATH_TO_PYTHON\python.exe` - - Alternatively, you can pip install to the currently activated - environment. If you have configured VSCode to use a virtual environment, - it should automatically activate it when you open a new terminal, so - running the `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 recognised - -You pip installed a command line program like `PyInstaller` or `black` that is -intended to be run from the command line, but it does not work. Two common causes -for this are: - -- You are using Python from the Microsoft Store +- #### Are you installing to the same environment you're running your code from? - To check if this is the case, type `pip -V`. If the path output includes - something like - `PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0`, you - are using Python from the Microsoft Store. To fix this you will either have - to use the full path to the scripts you want to use, or uninstall the - Microsoft Store Python and install Python properly with the online - installer. + This is a very common issue. When you install a module from PyPI, you will install it into a single Python + environment, the one that the `pip` you invoked is part of. This could be different to the one you are running the + script from if it's using a different Python installation, or a virtual environment. + + ##### I'm using PyCharm + + > PyCharm creates a virtual environment for each project by default, so if you're installing a module using Pycharm + > you need to make sure you also run your code through PyCharm. This also applies the other way round, if you want + > to use a module in PyCharm you need to install it through PyCharm. + > + > It's also possible to change PyCharm to use your system environment, see [their guide on configuring your + > interpreter](https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html) for more information. + + ##### I installed the module using pip from the command line + + > Run `pip -V` and look at the path returned it should be in the form `\Lib\site-packages\pip`. + > + > Then put `import sys;print(sys.executable);sys.exit(0);` at the top (above imports!) of your python file, and run + > it. The result should be in the form `\python.exe`. + > + > Now compare that `PATH_TO_PYTHON` to the one from `pip -V`. If they're different, this is the cause of the + > `ModuleNotFoundError`. Follow the relevant "I'm running my code with ..." section below for how to fix this. + + ##### I'm running my code with `python` from the terminal. + + > If you are using a virtual environment, ensure you have activated it before running `pip install`. You can test + > this by running `pip -V` and checking the path is the one of your virtual environment. + > + > Alternatively, you can use the `py` command to specify the python version you want to pip install into, e.g. + > `py -3.9 -m pip install numpy`, and to specify the executable you want to run your code with, e.g. + > `py -3.9 my_script.py`. + > + > If your `pip` and `python` commands are referring to different python environments at the same time, it's possible + > your PATH is configured incorrectly. See our [guide for adding Python to PATH](../putting-python-on-path) for + > how to fix this. + + ##### I'm running my code with the button in VSCode + + > To run your code from the same environment you installed Python to, set the VSCode Python interpreter to the one + > at the path you found when running `pip -V` by following [this + > guide](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment) (basically + > `Ctrl+Shift+P -> Python: Select Interpreter -> select the one desired`). The path should be in the form + > `PATH_TO_PYTHON\python.exe` + > + > Alternatively, you can pip install to the currently activated environment. If you have configured VSCode to use a + > virtual environment, it should automatically activate it when you open a new terminal, so running the + > `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 + +You pip installed a command line program like [`pyinstaller`](https://pypi.org/project/pyinstaller/) or +[`black`](https://pypi.org/project/black/) that is intended to be run from the command line, but it does not work. Two +common causes for this are: + +- You are using Python from the Microsoft Store ([which we don't recommend](../miscrosoft-store)). + + To check if this is the case, type `pip -V`. If the path output includes something like + `PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0`, you are using Python from the Microsoft + Store. To fix this you will either have to use the full path to the scripts you want to use, or [uninstall the + Microsoft Store Python](/static/images/content/python-on-windows/ms_store_uninstall.png) and [install Python + properly](../installing-python) with a [python.org installer](https://www.python.org/downloads). - You manually modified your PATH Environment Variable incorrectly - If you added `Python` to PATH manually through environment variables, it is - possible that you only added the executable but not the `/Scripts` folder. - This would cause issues with `pip` and make command line tools not + If you added `Python` to PATH manually through environment variables, it is possible that you only added the + executable but not the `\Scripts` folder. This would cause issues with `pip` and make command line tools not accessible. Look at our [guide on adding Python to the - PATH](../python-on-windows.md#adding-python-to-your-path) for how to verify - and fix this. + PATH](../putting-python-on-path/#advanced-method-manually-edit-the-path) for how to verify and fix this. -Projects that add a command line program usually work by adding an executable to -the `/Scripts` folder of your Python install. If you clicked "Add to PATH" when -installing Python this folder will have been added to PATH, so anything there -should be runnable directly from the command line. This should also be the case -when using a virtual environment, as long as it is properly activated. +Projects that add a command line program usually work by adding an executable to the `\Scripts` folder of your Python +install (the full path of which is `C:\Users\\AppData\Local\Programs\Python\Python311\Scripts` in a default 3.11 +install). If you checked "Add python.exe to PATH" when installing Python, this folder will have been added to PATH, so +anything there should be runnable directly from the command line. Virtual environments also have their own `\Scripts` +directories that things can be installed to and are effectively on the PATH when the venv is properly activated. ### 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 loop). This lets you run `Python` code line by line without -having to create a file. +When you type `python` in the terminal you enter into the python REPL ([read-evaluate-print +loop](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)), also known as the Python console. This lets +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 the terminal, not in -the Python REPL. To exit the REPL, type `exit()` and press enter. You should -then be able to run your commands normally. +General commands like `pip` and `python` should be run in the normal terminal, not in the Python REPL. It usually has +`>>>` at the start of each line. To exit the REPL, type `exit()` and press enter. You should then be able to run your +commands normally, unless it was the Python App, in which case it will close completely and you'll need to open a +terminal like PowerShell or Command Prompt separately. ### I tried to uninstall Python by deleting the folder, now it doesn't work and I can't reinstall it! -You should never uninstall your Python installation by deleting the folder it is -in. If you have, you may need to edit Registry Keys to fully remove the -installation. Doing this is dangerous and beyond the scope of this guide. +You should never uninstall your Python installation by deleting the folder it is in. If you have, you may need to edit +Registry Keys to fully remove the installation. Doing this is dangerous and beyond the scope of this guide. -To uninstall Python properly, run the installer for the version you want to -uninstall and select "uninstall". If you no longer have the installer, you can -re-download it first. +To uninstall Python properly, run the installer for the version you want to uninstall and select "uninstall". If you no +longer have the installer, you can [re-download it from python.org](https://www.python.org/downloads/windows/) first. -- cgit v1.2.3 From 4d734b047c8825fad94374aa8aa61a339951c60f Mon Sep 17 00:00:00 2001 From: discretegames Date: Mon, 7 Nov 2022 15:19:00 -0800 Subject: tweaks and link fixes to windows guides, still in reorg process --- .../python-guides/windows/installing-python.md | 15 ++++---- .../python-guides/windows/microsoft-store.md | 21 ++++++----- .../windows/putting-python-on-path.md | 39 ++++++++++++--------- .../guides/python-guides/windows/py-launcher.md | 8 ++--- .../python-guides/windows/unix-env-on-windows.md | 6 ++-- .../python-on-windows/testing_path_worked_2.png | Bin 27470 -> 28472 bytes .../python-on-windows/testing_path_worked_3.png | Bin 0 -> 28868 bytes 7 files changed, 48 insertions(+), 41 deletions(-) create mode 100644 pydis_site/static/images/content/python-on-windows/testing_path_worked_3.png diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md index e9cf6343..e262d287 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md @@ -4,10 +4,13 @@ description: How we recommend installing Python on Windows icon: fab fa-windows --- -The recommended way to install Python on windows is directly from the -[Python website's Downloads page](https://www.python.org/downloads/windows/). -Installing Python from the Microsoft Store is not recommended as it can -[cause issues](../microsoft-store.md). +Our recommended way of installing Python on Windows is using a full installer from the official [python.org Downloads +page](https://www.python.org/downloads/). Installing Python from the [Microsoft +Store](https://apps.microsoft.com/store/search/python) is _not_ recommended as [it can cause various +issues](../microsoft-store). + +On [python.org/downloads](https://python.org/downloads), click the big yellow "Download Python 3.x.x" button near the top of the page and it should automatically start a download of the installer for the latest stable version of Python +that best suits your computer. ## Selecting an Installer @@ -56,7 +59,7 @@ Python installation on your PATH and don't want this one to override it, don't tick this. If you installed Python without adding to PATH and now want to add it, see -[our guide on adding Python to PATH](../python-on-windows.md#adding-python-to-your-path). +[our guide on adding Python to PATH](../putting-python-on-path). Then simply click install, and wait for the install to finish! @@ -64,5 +67,5 @@ To test your installation, type "cmd" in the windows search bar and select "Command Prompt" to open a terminal (make sure it's opened _after_ installation has finished) type `python -V`, and press enter. If it outputs your python version, you've successfully installed Python. (if you didn't add to PATH, you -can use [the py launcher](../python-on-windows.md#the-py-launcher) to test +can use [the py launcher](../py-launcher) to test instead). diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md index e4bac067..e77fe963 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md @@ -7,13 +7,12 @@ icon: fab fa-windows [](/static/images/content/python-on-windows/ms_store_drake.png) -Microsoft provides versions of Python for Windows -[on the Microsoft Store](https://apps.microsoft.com/store/search/python) as an alternative to using the -[full installer from python.org](https://www.python.org/downloads). **We recommend you install Python on Windows using the -[full installer from python.org](https://www.python.org/downloads), -and not from the Microsoft store wherever possible!** +Microsoft provides versions of Python for Windows [on the Microsoft +Store](https://apps.microsoft.com/store/search/python) as an alternative to using the [full installer from +python.org](https://www.python.org/downloads). **We recommend you install Python on Windows using the [full installer +from python.org](https://www.python.org/downloads), and not from the Microsoft store wherever possible!** -You can follow [this guide to install Python from python.org](../install-on-windows.md) and more Python Windows releases +You can follow [this guide to install Python from python.org](../installing-python) and more Python Windows releases can be found [here](https://www.python.org/downloads/windows). Here are some common issues with using Python from the Microsoft Store: @@ -27,9 +26,8 @@ Here are some common issues with using Python from the Microsoft Store: - ##### It can cause issues with permissions - Some modules and scripts wont work with it because of restricted permissions. - This is explained - [in the Python documentation](https://docs.python.org/3/using/windows.html#redirection-of-local-data-registry-and-temporary-paths) + Some modules and scripts wont work with it because of restricted permissions. This is explained [in the Python + documentation](https://docs.python.org/3/using/windows.html#redirection-of-local-data-registry-and-temporary-paths) - ##### It can cause Path confusion @@ -43,7 +41,8 @@ Here are some common issues with using Python from the Microsoft Store: `C:\Users\\AppData\Local\Programs\Python\Python311\Scripts` (for Python 3.11). If for some reason you want both installed, put the ones you want the commands for higher up in Path. - You can find the path of the executable for a version of Python by running `import sys; print(sys.executable)` in it. + You can find the path of the executable for a version of Python by running `import sys; print(sys.executable)` in + it. - ##### Confusing app execution alias behaviour @@ -67,6 +66,6 @@ Here are some common issues with using Python from the Microsoft Store: If you have the Microsoft Store version of Python and want to uninstall it, you can search "uninstall" in the Start menu to open up the "Apps & features" settings and filter by "python". The Python app that has a console in the icon and -"Python Software Foundation" under the name is the Microsoft Store one (see image below). Click it and hit Uninstall. +"Python Software Foundation" under the name is the Microsoft Store one. Click it and hit Uninstall. ![Which version is which when uninstalling Python](/static/images/content/python-on-windows/ms_store_uninstall.png) 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 b78fc5d4..fc921623 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 @@ -5,10 +5,8 @@ icon: fab fa-windows toc: 2 --- - - 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 +recommended way](../installing-python)) 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. @@ -16,7 +14,7 @@ pip : The term 'pip' is not recognized as the name of a cmdlet, function, script 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 +Store](../microsoft-store#confusing-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. @@ -72,7 +70,7 @@ still need to locate the installer exe at step 5 if it's not already in Download ### Verifying your changes -To check that it worked, open a fresh terminal — Command Prompt, Powershell, an IDE-integrated terminal, [Windows +To check that it worked, open a fresh 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 @@ -90,19 +88,24 @@ and you should see the versions of Python and pip that you just added to Path: ![Checking Python and pip versions.](/static/images/content/python-on-windows/testing_path_worked_1.png) -You can also run Python with `python`, and then after `>>>` in the Python REPL, run +Running `Get-Command python` in PowerShell, or `where python` in Command Prompt, you +can see where that terminal is finding the `python.exe` it would run when a `python` command is given: + +![Get-Command/where Python.](/static/images/content/python-on-windows/testing_path_worked_2.png) + +(`where` in fact lists all the Pythons it finds, even the dummy [app execution +alias](../microsoft-store#confusing-app-execution-alias-behaviour) one that opens the Microsoft Store.) + +You can also run Python with `python` (not `py` as that may start a different version, see more +[here](.../py-launcher)), and then after `>>>` in the Python REPL, run ```py -import sys; print(sys.executable) +import sys; print(sys.executable); exit(); ``` to see that the exact executable that is currently running Python is what you expect: -![Checking Python executable.](/static/images/content/python-on-windows/testing_path_worked_2.png) - -Type `exit()` from here to go back to the normal terminal. - - +![Checking Python executable.](/static/images/content/python-on-windows/testing_path_worked_3.png) Of course your username will probably not be "r", and your executable path may differ from `C:\Users\\AppData\Local\Programs\Python\Python311` depending on where you chose to install Python and what @@ -142,7 +145,7 @@ foobar: The term 'foobar' is not recognized as the name of a cmdlet, function, s ``` Or, in the case of not finding `python`, it may [open up the Microsoft -store](../microsoft-store.md#confusing-app-execution-alias-behaviour). +store](../microsoft-store#confusing-app-execution-alias-behaviour). Again, the Path lookup order is: @@ -220,8 +223,9 @@ Follow these steps to add Python to the Path: This step may not be strictly necessary, but remember that command lookup happens in order from top to bottom. Python is often bundled with other software that may end up on the Path, so there's there could be another - `python.exe` in one of of the other folders on the path that gets in the way. (This exact thing has happened to me when - I put `C:\Program Files\Inkscape\bin` on my Path, as [Inkscape](https://inkscape.org/) comes with a copy of Python.) + `python.exe` in one of of the other folders on the path that gets in the way. (This exact thing has happened to me + when I put `C:\Program Files\Inkscape\bin` on my Path, as [Inkscape](https://inkscape.org/) comes with a copy of + Python.) Also, the System Path comes first in command lookup, so to be certain you to may want to go back and check the System Path (see step 5) and _carefully_ delete any entry that is a Python executable path blocking the one you just @@ -232,10 +236,13 @@ Follow these steps to add Python to the Path: 9. Finish by making sure to hit "OK" on each of the thee "Edit environment variable", "Environment Variable", and "System Properties" windows, and then you're done! - Python and Python Scripts should not be on your Path! **You will need to restart any terminals or editors you have open before they detect the change.** + Python and Python Scripts should not be on your Path! **You will need to restart any terminals or editors you have + open before they detect the change.** At this point you can [verify your changes in the same way as detailed above](#verifying-your-changes). Hopefully it works! (These steps were written with Windows 10 and Python 3.11 in mind, but they should be identical or similar for Windows 11 and other recent versions of Python.) + + 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 388177ec..99d6deda 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,12 +1,10 @@ --- -title: The py Launcher on Windows -description: Common commands and usage of the Windows "py" Python launcher +title: The py Launcher +description: Common commands and usage of the "py" Python launcher on Windows icon: fab fa-windows --- -When you install Python on Windows fron - -TODO!!! rewrite/rearrange to be all about the py command + ## The py launcher diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md b/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md index f52ddfed..d959d1f6 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md @@ -4,8 +4,6 @@ description: How to setup a Unix-style Python environment ready to start coding icon: fab fa-windows --- - - Many programmers use Linux or macOS operating systems for their work, though newcomers to programming will likely want to get started on the computer they already own, which will often be running Windows. @@ -17,7 +15,7 @@ command prompt called Git Bash, which will support many of the commands availabl ## Installing Python First you'll need to install Python. We recommend installing from the Python website, you can follow our guide on how to -do this [here](../install-on-windows.md). +do this [here](../installing-python). ## Installing a text editor @@ -70,3 +68,5 @@ location, you can use the `cd` command ("cd" stands for "change directory") to n desktop, `cd /c/Users/YourUsername/Desktop` will take you there. Otherwise if you have the directory open in your file explorer, you can right click anywhere in the white space of the file explorer window (not on top of a file) and select "Git Bash Here". Once you're there, type `python hello.py`, and the program will run. + + 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 index 7c71a331..465a873c 100644 Binary files a/pydis_site/static/images/content/python-on-windows/testing_path_worked_2.png and b/pydis_site/static/images/content/python-on-windows/testing_path_worked_2.png differ diff --git a/pydis_site/static/images/content/python-on-windows/testing_path_worked_3.png b/pydis_site/static/images/content/python-on-windows/testing_path_worked_3.png new file mode 100644 index 00000000..25493102 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/testing_path_worked_3.png differ -- cgit v1.2.3 From f1961a0c7c581d74e654fb7a24938f35f7be786e Mon Sep 17 00:00:00 2001 From: discretegames Date: Mon, 7 Nov 2022 16:10:46 -0800 Subject: reorg of windows guides, moved py launcher into installing and using, fixed links --- .../guides/python-guides/windows/common-issues.md | 15 ++-- .../windows/installing-and-using-python.md | 87 ++++++++++++++++++++++ .../python-guides/windows/installing-python.md | 71 ------------------ .../python-guides/windows/microsoft-store.md | 4 +- .../windows/putting-python-on-path.md | 4 +- .../guides/python-guides/windows/py-launcher.md | 50 ------------- .../python-guides/windows/unix-env-on-windows.md | 4 +- 7 files changed, 101 insertions(+), 134 deletions(-) create mode 100644 pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md delete mode 100644 pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md delete mode 100644 pydis_site/apps/content/resources/guides/python-guides/windows/py-launcher.md diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md index 4d8530d5..dcf94f73 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -1,5 +1,5 @@ --- -title: Common issues using Python on Windows +title: Common Issues Using Python on Windows description: A list of common issues with Python on Windows and how to fix them icon: fab fa-windows --- @@ -19,12 +19,12 @@ If after doing this you have an issue with the Python command not being detected ### 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-python). +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](../py-launcher) for more information on that. +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. ### I `pip` installed a package but when running my code get a `ModuleNotFoundError` @@ -36,7 +36,8 @@ replacing `python` in your command with `py`. See [this guide](../py-launcher) f If your code runs fine, you could try restarting your editor. If you have newly installed a module it may just not have detected it yet. If that doesn't help, you may need to configure your editor to ensure it is looking for the - module in the correct Python environment. See [our guide on virtual environments](dg:TODO) for more information. + module in the correct Python environment. See [our guide on virtual + environments](../installing-and-using-python/#virtual-environments) for more information. - #### Was the install successful? @@ -126,7 +127,7 @@ common causes for this are: `PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0`, you are using Python from the Microsoft Store. To fix this you will either have to use the full path to the scripts you want to use, or [uninstall the Microsoft Store Python](/static/images/content/python-on-windows/ms_store_uninstall.png) and [install Python - properly](../installing-python) with a [python.org installer](https://www.python.org/downloads). + properly](../installing-and-using-python) with a [python.org installer](https://www.python.org/downloads). - You manually modified your PATH Environment Variable incorrectly diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md new file mode 100644 index 00000000..6eb87b86 --- /dev/null +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -0,0 +1,87 @@ +--- +title: Installing and Using Python on Windows +description: How we recommend installing Python on Windows, and how to use Python Windows features +icon: fab fa-windows +--- + + + +Our recommended way of installing Python on Windows is using a full installer from the official [python.org Downloads +page](https://www.python.org/downloads/). Installing Python from the [Microsoft +Store](https://apps.microsoft.com/store/search/python) is _not_ recommended as [it can cause various +issues](../microsoft-store). + +On [python.org/downloads](https://python.org/downloads), click the big yellow "Download Python 3.x.x" button near the top of the page and it should automatically start a download of the installer for the latest stable version of Python +that best suits your computer. + +## Selecting an Installer + +There are many different installer options available from the downloads page. +You should usually select the "Windows installer" option instead of the "Windows +embeddable package". Some minor versions may not + +### Which version? + +Current Python versions follow the form `3.minor.micro`. Major releases happen +yearly and provide new features and breaking changes, whilst minor releases are +more common and only include bug/security fixes. + +Installing the latest major version will give you access to Python's newest +features. However, some modules may not support the newest versions straight +away, so installing the second latest will help you avoid those issues. If you +find you want some newer features or your module does not support your current +version, you can always install another version as well. + +You should generally always install the newest minor version, although some may +not provide an installer in which case you should find the newest that does. + +### 32-bit vs 64-bit? + +Install 64-bit python unless you have reason not to. With 32 bit you may run +into memory limits if doing intensive operations (Python will be limited to +using 4GB of memory), and some installed modules may not offer prebuilt wheels +for 32 bit, potentially making installs slower or meaning you have to install +build dependencies. + +If you get an error when installing 64-bit Python, your computer may not support +it. To find out if this is the case, search "About your PC" in windows search +and open the settings page. Then look for the "System Type" option under "Device +Specifications". It should say "64-bit operating system, x64-based processor" if +you have support. You need a 64 bit processor and OS to install 64 bit programs. + +## Running the installer + +When you run the installer you should see a screen like this: + +![python_installer_screen](https://user-images.githubusercontent.com/22353562/126144479-cfe6bd98-6d2e-47c3-b6b3-5de9f2656e9a.png) + +Make sure you tick "Add Python 3.x to Path". This allows you to use the `python` +and `pip` commands in your terminal to invoke Python. If you already have a +Python installation on your PATH and don't want this one to override it, don't +tick this. + +If you installed Python without adding to PATH and now want to add it, see +[our guide on adding Python to PATH](../putting-python-on-path). + +Then simply click install, and wait for the install to finish! + +To test your installation, type "cmd" in the windows search bar and select "Command Prompt" to open a terminal (make +sure it's opened _after_ installation has finished) type `python -V`, and press enter. If it outputs your python +version, you've successfully installed Python. (if you didn't add to PATH, you can use [the py +launcher](../installing-and-using-python/#the-py-launcher) to test instead). + +## The py Launcher + +dg:TODO + +## Virtual Environments + +dg:TODO diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md deleted file mode 100644 index e262d287..00000000 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-python.md +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: Installing Python on Windows -description: How we recommend installing Python on Windows -icon: fab fa-windows ---- - -Our recommended way of installing Python on Windows is using a full installer from the official [python.org Downloads -page](https://www.python.org/downloads/). Installing Python from the [Microsoft -Store](https://apps.microsoft.com/store/search/python) is _not_ recommended as [it can cause various -issues](../microsoft-store). - -On [python.org/downloads](https://python.org/downloads), click the big yellow "Download Python 3.x.x" button near the top of the page and it should automatically start a download of the installer for the latest stable version of Python -that best suits your computer. - -## Selecting an Installer - -There are many different installer options available from the downloads page. -You should usually select the "Windows installer" option instead of the "Windows -embeddable package". Some minor versions may not - -### Which version? - -Current Python versions follow the form `3.minor.micro`. Major releases happen -yearly and provide new features and breaking changes, whilst minor releases are -more common and only include bug/security fixes. - -Installing the latest major version will give you access to Python's newest -features. However, some modules may not support the newest versions straight -away, so installing the second latest will help you avoid those issues. If you -find you want some newer features or your module does not support your current -version, you can always install another version as well. - -You should generally always install the newest minor version, although some may -not provide an installer in which case you should find the newest that does. - -### 32-bit vs 64-bit? - -Install 64-bit python unless you have reason not to. With 32 bit you may run -into memory limits if doing intensive operations (Python will be limited to -using 4GB of memory), and some installed modules may not offer prebuilt wheels -for 32 bit, potentially making installs slower or meaning you have to install -build dependencies. - -If you get an error when installing 64-bit Python, your computer may not support -it. To find out if this is the case, search "About your PC" in windows search -and open the settings page. Then look for the "System Type" option under "Device -Specifications". It should say "64-bit operating system, x64-based processor" if -you have support. You need a 64 bit processor and OS to install 64 bit programs. - -## Running the installer - -When you run the installer you should see a screen like this: - -![python_installer_screen](https://user-images.githubusercontent.com/22353562/126144479-cfe6bd98-6d2e-47c3-b6b3-5de9f2656e9a.png) - -Make sure you tick "Add Python 3.x to Path". This allows you to use the `python` -and `pip` commands in your terminal to invoke Python. If you already have a -Python installation on your PATH and don't want this one to override it, don't -tick this. - -If you installed Python without adding to PATH and now want to add it, see -[our guide on adding Python to PATH](../putting-python-on-path). - -Then simply click install, and wait for the install to finish! - -To test your installation, type "cmd" in the windows search bar and select -"Command Prompt" to open a terminal (make sure it's opened _after_ installation -has finished) type `python -V`, and press enter. If it outputs your python -version, you've successfully installed Python. (if you didn't add to PATH, you -can use [the py launcher](../py-launcher) to test -instead). diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md index e77fe963..9620c09f 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md @@ -1,5 +1,5 @@ --- -title: Why not to install Python from the Microsoft Store +title: Why Not to Install Python from the Microsoft Store description: The drawbacks of installing the Microsoft Store versions of Python icon: fab fa-windows --- @@ -12,7 +12,7 @@ Store](https://apps.microsoft.com/store/search/python) as an alternative to usin python.org](https://www.python.org/downloads). **We recommend you install Python on Windows using the [full installer from python.org](https://www.python.org/downloads), and not from the Microsoft store wherever possible!** -You can follow [this guide to install Python from python.org](../installing-python) and more Python Windows releases +You can follow [this guide to install Python from python.org](../installing-and-using-python) and more Python Windows releases can be found [here](https://www.python.org/downloads/windows). Here are some common issues with using Python from the Microsoft Store: 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 fc921623..5543ee16 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 @@ -6,7 +6,7 @@ toc: 2 --- If you're on Windows and know you have [Python installed from python.org](https://www.python.org/downloads/) ([our -recommended way](../installing-python)) but you're still getting errors like +recommended way](../installing-and-using-python)) 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. @@ -97,7 +97,7 @@ can see where that terminal is finding the `python.exe` it would run when a `pyt alias](../microsoft-store#confusing-app-execution-alias-behaviour) one that opens the Microsoft Store.) You can also run Python with `python` (not `py` as that may start a different version, see more -[here](.../py-launcher)), and then after `>>>` in the Python REPL, run +[here](../installing-and-using-python/#the-py-launcher)), and then after `>>>` in the Python REPL, run ```py import sys; print(sys.executable); exit(); 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 deleted file mode 100644 index 99d6deda..00000000 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/py-launcher.md +++ /dev/null @@ -1,50 +0,0 @@ ---- -title: The py Launcher -description: Common commands and usage of the "py" Python launcher on Windows -icon: fab fa-windows ---- - - - -## The py launcher - -By default, Python installed on Windows using the online Python installer comes -with the "py launcher". It is a command line tool you invoke using the `py` -command, and helps you invoke a specific python version. - -It provides the `py -0p` command. This lists the python versions you have -installed, the output will look like this: - - C:\Users\username>py -0p - Installed Pythons found by py Launcher for Windows - -V:3.11 C:\Users\username\AppData\Local\Programs\Python\Python311\python.exe - -V:3.10 C:\Users\username\AppData\Local\Programs\Python\Python310\python.exe - -V:3.9 * C:\Users\username\AppData\Local\Programs\Python\Python39\python.exe - -The versions will be ordered from newest to oldest, and the `*` will indicate -which version running `py` will call by default. This depends on the following -requirements, and may not be the same version you get from running `python` (if -you get any): - -```text -If an exact version is not given, using the latest version can be overridden by -any of the following, (in priority order): -• An active virtual environment -• A shebang line in the script (if present) -• With -2 or -3 flag a matching PY_PYTHON2 or PY_PYTHON3 Environment variable -• A PY_PYTHON Environment variable -• From [defaults] in py.ini in your %LOCALAPPDATA%\py.ini -• From [defaults] in py.ini beside py.exe (use `where py` to locate) -``` - -You can override which version is called by specifying the major and minor -versions to used. For example, to invoke python 3.7, you could run `py -3.7`. -You can then pass any arguments to `python` on top of that, for example -`py -3.7 myscript.py` to run `myscript.py`, or `py -3.7 -m pip install numpy` -to invoke `pip` to install numpy into that version. - -You can use `py` instead of `python` and not have any python versions on PATH at -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) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md b/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md index d959d1f6..47f2138e 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md @@ -1,5 +1,5 @@ --- -title: Setting up a Unix-style Python Environment on Windows +title: Setting up a Unix-Style Python Environment on Windows description: How to setup a Unix-style Python environment ready to start coding in icon: fab fa-windows --- @@ -15,7 +15,7 @@ command prompt called Git Bash, which will support many of the commands availabl ## Installing Python First you'll need to install Python. We recommend installing from the Python website, you can follow our guide on how to -do this [here](../installing-python). +do this [here](../installing-and-using-python). ## Installing a text editor -- cgit v1.2.3 From 4bb5c570a24d75e48c564140b4498bd592102bd8 Mon Sep 17 00:00:00 2001 From: discretegames Date: Mon, 7 Nov 2022 16:12:41 -0800 Subject: added toc to windows guides --- .../apps/content/resources/guides/python-guides/windows/common-issues.md | 1 + .../guides/python-guides/windows/installing-and-using-python.md | 1 + 2 files changed, 2 insertions(+) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md index dcf94f73..f86d5d48 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -2,6 +2,7 @@ title: Common Issues Using Python on Windows description: A list of common issues with Python on Windows and how to fix them icon: fab fa-windows +toc: 3 --- ### When I run `python` in the terminal I get no result, or the Windows Store opens! diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md index 6eb87b86..59c0cad5 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -2,6 +2,7 @@ title: Installing and Using Python on Windows description: How we recommend installing Python on Windows, and how to use Python Windows features icon: fab fa-windows +toc: 2 --- +You may also want to check out our guides on [Common Issues Using Python on Windows](../common-issues), [Adding Python +to the Windows Path](../putting-python-on-path.md), and Setting up a [Unix-Style Environment on +Windows](../unix-env-on-windows.md). -Our recommended way of installing Python on Windows is using a full installer from the official [python.org Downloads -page](https://www.python.org/downloads/). Installing Python from the [Microsoft -Store](https://apps.microsoft.com/store/search/python) is _not_ recommended as [it can cause various -issues](../microsoft-store). +## Recommended Install + +Follow the steps below to install the latest version of Python on Windows. + +(The instructions were written with Windows 10 and Python 3.11.0 in mind, but should be nearly or fully identical on +Windows 11 and other modern versions of Python.) + +> If you want a fresh start, you may want to first uninstall any other versions of Python on your PC, including those from +> the Microsoft Store, if you have any. This can be done in the ["Apps & features" Windows +> settings](/static/images/content/python-on-windows/ms_store_uninstall.png) (type "apps and features" into the Start Menu +> to find it). Though it's fine to have multiple versions of Python installed at once. It can be useful for testing +> version compatibility or for working on projects made in a certain version. Only uninstall things if you want to. + +1. Go to [python.org/downloads](https://www.python.org/downloads) and click the big yellow "Download Python 3.x.x" + button near the top of the page. That should start the download of the latest Windows Python installer that best + suits your computer. + + If you want a different version or it doesn't work for some reason, you can download the + Windows installer you want from [python.org/downloads/windows](https://www.python.org/downloads/windows). + + [![Step 1](/static/images/content/python-on-windows/recommended_install_1.png)](/static/images/content/python-on-windows/recommended_install_1.png) + +2. When it finishes downloading, click the file in your browser or find it in your Downloads folder and double-click it to start the installer. + + [![Step 2](/static/images/content/python-on-windows/recommended_install_2.png)](/static/images/content/python-on-windows/recommended_install_2.png) + +3. Check the "Add python.exe to PATH" checkbox (the text may differ slightly depending on your installer). This will + make it so the command line can recognize commands like `python` and `pip`. (Read [this + guide](../putting-python-on-path) to learn more.) + + [![Step 3](/static/images/content/python-on-windows/recommended_install_3.png)](/static/images/content/python-on-windows/recommended_install_3.png) + +4. Then click the big "Install Now" button. Aside from adding Python to PATH, the rest of the installer defaults are + usually fine, so there's no need to customize the installation unless you want to. + + [![Step 4](/static/images/content/python-on-windows/recommended_install_4.png)](/static/images/content/python-on-windows/recommended_install_4.png) + +5. It will take a minute to install and then (hopefully) say "Setup was successful". Congrats, you just installed + Python! You can close the installer. + + [![Step 5 A](/static/images/content/python-on-windows/recommended_install_5.png)](/static/images/content/python-on-windows/recommended_install_5.png) + [![Step 5 B](/static/images/content/python-on-windows/recommended_install_6.png)](/static/images/content/python-on-windows/recommended_install_6.png) + +### Checking that it Worked + +To test that installing Python worked, you can do what it suggests and search "python" on the Start Menu to find the Python console app +and run some code like `print("Hello, World!")`. + +[![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 `py` or `python` in a new terminal window to open up the Python +[REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop), or use `python somefile.py` to run some +Python file (if `py` runs the wrong version of Python, [see below](#the-py-launcher) for how to change the default). Use +whichever terminal you prefer: Command Prompt, PowerShell, an IDE-integrated terminal, [Windows +Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701). It just has to be a freshly opened +terminal or the commands may not be recognized. + +[![Testing py and python](/static/images/content/python-on-windows/recommended_install_8.png)](/static/images/content/python-on-windows/recommended_install_8.png) + +You can double check what versions of Python and [pip](https://pip.pypa.io/en/stable/) were installed by running `python -V` or `pip -V` in a terminal: + +[![Checking python and pip versions](/static/images/content/python-on-windows/testing_path_worked_1.png)](/static/images/content/python-on-windows/testing_path_worked_1.png) + +And finally, it's worth searching and opening "IDLE" on the Start Menu, which is the the basic +[IDE](https://en.wikipedia.org/wiki/Integrated_development_environment) that comes with Python. Most people end up using +[PyCharm](https://www.jetbrains.com/pycharm/) or [VSCode](https://code.visualstudio.com/) to program in Python but IDLE +is a great starting point. + +[![Testing IDLE](/static/images/content/python-on-windows/recommended_install_9.png)](/static/images/content/python-on-windows/recommended_install_9.png) -On [python.org/downloads](https://python.org/downloads), click the big yellow "Download Python 3.x.x" button near the top of the page and it should automatically start a download of the installer for the latest stable version of Python -that best suits your computer. +## More Installation Information -## Selecting an Installer +### Selecting an Installer There are many different installer options available from the downloads page. You should usually select the "Windows installer" option instead of the "Windows @@ -58,7 +127,7 @@ and open the settings page. Then look for the "System Type" option under "Device Specifications". It should say "64-bit operating system, x64-based processor" if you have support. You need a 64 bit processor and OS to install 64 bit programs. -## Running the installer +### Running the installer When you run the installer you should see a screen like this: 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 5543ee16..3c8face0 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 @@ -1,5 +1,5 @@ --- -title: Putting Python on Path +title: Adding Python to the Path description: How to make sure Python is properly on the Windows Path environment variable icon: fab fa-windows toc: 2 diff --git a/pydis_site/static/images/content/python-on-windows/recommended_install_1.png b/pydis_site/static/images/content/python-on-windows/recommended_install_1.png new file mode 100644 index 00000000..65601cec Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/recommended_install_1.png differ diff --git a/pydis_site/static/images/content/python-on-windows/recommended_install_2.png b/pydis_site/static/images/content/python-on-windows/recommended_install_2.png new file mode 100644 index 00000000..54b58a39 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/recommended_install_2.png differ diff --git a/pydis_site/static/images/content/python-on-windows/recommended_install_3.png b/pydis_site/static/images/content/python-on-windows/recommended_install_3.png new file mode 100644 index 00000000..2e8f45d9 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/recommended_install_3.png differ diff --git a/pydis_site/static/images/content/python-on-windows/recommended_install_4.png b/pydis_site/static/images/content/python-on-windows/recommended_install_4.png new file mode 100644 index 00000000..4b35e122 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/recommended_install_4.png differ diff --git a/pydis_site/static/images/content/python-on-windows/recommended_install_5.png b/pydis_site/static/images/content/python-on-windows/recommended_install_5.png new file mode 100644 index 00000000..ded0b5ff Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/recommended_install_5.png differ diff --git a/pydis_site/static/images/content/python-on-windows/recommended_install_6.png b/pydis_site/static/images/content/python-on-windows/recommended_install_6.png new file mode 100644 index 00000000..b11e62ec Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/recommended_install_6.png differ diff --git a/pydis_site/static/images/content/python-on-windows/recommended_install_7.png b/pydis_site/static/images/content/python-on-windows/recommended_install_7.png new file mode 100644 index 00000000..3091ac08 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/recommended_install_7.png differ diff --git a/pydis_site/static/images/content/python-on-windows/recommended_install_8.png b/pydis_site/static/images/content/python-on-windows/recommended_install_8.png new file mode 100644 index 00000000..a6717670 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/recommended_install_8.png differ diff --git a/pydis_site/static/images/content/python-on-windows/recommended_install_9.png b/pydis_site/static/images/content/python-on-windows/recommended_install_9.png new file mode 100644 index 00000000..1d37f692 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/recommended_install_9.png differ -- cgit v1.2.3 From 3dc24ec00238c969063302fbeed3aa24b2537a9a Mon Sep 17 00:00:00 2001 From: discretegames Date: Mon, 7 Nov 2022 21:49:03 -0800 Subject: completed more install info section of Windows guide --- .../windows/installing-and-using-python.md | 87 +++++++++++----------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md index b72d0b23..23c9e8df 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -2,7 +2,7 @@ title: Installing and Using Python on Windows description: How we recommend installing Python on Windows, and how to use Python Windows features icon: fab fa-windows -toc: 2 +toc: 3 --- Our recommended way of installing Python on a Windows operating system is using the full installer from the official @@ -24,8 +24,8 @@ Windows](../unix-env-on-windows.md). Follow the steps below to install the latest version of Python on Windows. -(The instructions were written with Windows 10 and Python 3.11.0 in mind, but should be nearly or fully identical on -Windows 11 and other modern versions of Python.) +(The instructions were written with Windows 10 and Python 3.11.0 in mind, but should be nearly or fully identical with +Windows 11 or other modern versions of Python.) > If you want a fresh start, you may want to first uninstall any other versions of Python on your PC, including those from > the Microsoft Store, if you have any. This can be done in the ["Apps & features" Windows @@ -94,59 +94,60 @@ is a great starting point. ### Selecting an Installer -There are many different installer options available from the downloads page. -You should usually select the "Windows installer" option instead of the "Windows -embeddable package". Some minor versions may not +At [python.org/downloads/windows](https://www.python.org/downloads/windows/) there are many different Windows Python +installer options available. A link to the latest release page is listed at the top, for example [the Python 3.11.0 +release page](https://www.python.org/downloads/release/python-3110/) has info about new features with downloads at the +bottom. Back on the list of all Windows releases, pre-releases are on the right if you want to try cutting-edge (and +possibly unstable) versions of Python, and stables releases are on the left, all the way back to Python 2.0.1 from 2001. +Some minor versions may not have installers available. -### Which version? +You should usually select the "Windows installer" option instead of the "Windows embeddable package". Check out [the +official docs on Using Python on Windows](https://docs.python.org/3/using/windows.html) for more details on other ways +to install Python on Windows. -Current Python versions follow the form `3.minor.micro`. Major releases happen -yearly and provide new features and breaking changes, whilst minor releases are -more common and only include bug/security fixes. +### Which Version? -Installing the latest major version will give you access to Python's newest -features. However, some modules may not support the newest versions straight -away, so installing the second latest will help you avoid those issues. If you -find you want some newer features or your module does not support your current -version, you can always install another version as well. +Current Python versions follow [the form `3.minor.micro`](https://peps.python.org/pep-0440/#final-releases) (similar to +[semantic versioning](https://semver.org/)), for example +[3.11.0](https://www.python.org/downloads/release/python-3110/). "3" is the major number and not about to change. Minor +releases happen yearly and provide new features and breaking changes, whilst micro releases are more common and only +include bug/security fixes. When people say "Python 3" they aren't necessarily specifying a minor or micro version, but +you can assume they mean the latest ones. -You should generally always install the newest minor version, although some may -not provide an installer in which case you should find the newest that does. +Installing the latest minor version will give you access to Python's newest features. However, some packages may not +support the newest versions straight away, so installing the second latest (for example, installing 3.10 when 3.11 is +the latest) will help you avoid those issues. If you find you want some newer features or your module does not support +your current version, you can always install another version as well. -### 32-bit vs 64-bit? - -Install 64-bit python unless you have reason not to. With 32 bit you may run -into memory limits if doing intensive operations (Python will be limited to -using 4GB of memory), and some installed modules may not offer prebuilt wheels -for 32 bit, potentially making installs slower or meaning you have to install -build dependencies. +You should generally always install the newest micro version, although some may not provide an installer, in which case +you should find the newest that does. -If you get an error when installing 64-bit Python, your computer may not support -it. To find out if this is the case, search "About your PC" in windows search -and open the settings page. Then look for the "System Type" option under "Device -Specifications". It should say "64-bit operating system, x64-based processor" if -you have support. You need a 64 bit processor and OS to install 64 bit programs. +### What about Python 2 and 4? -### Running the installer +Python 2 should not be used unless you are absolutely required to use it for legacy code or school. [It was officially +sunset January 1, 2020:](https://www.python.org/doc/sunset-python-2) -When you run the installer you should see a screen like this: +> As of January 1st, 2020 no new bug reports, fixes, or changes will be made to Python 2, and Python 2 is no longer +> supported. -![python_installer_screen](https://user-images.githubusercontent.com/22353562/126144479-cfe6bd98-6d2e-47c3-b6b3-5de9f2656e9a.png) +Python 2 code is not _that_ different from Python 3 code, notable differences being that `print` was a statement rather +than a function so it didn't need parentheses, and `input` evaluated the things inputted (unsafe!). Still, it's best +to try to not use learning resources written in Python 2, and definitely don't start new projects in Python 2. -Make sure you tick "Add Python 3.x to Path". This allows you to use the `python` -and `pip` commands in your terminal to invoke Python. If you already have a -Python installation on your PATH and don't want this one to override it, don't -tick this. +Python 4 is [not happening anytime soon](https://builtin.com/software-engineering-perspectives/python-4), if ever. -If you installed Python without adding to PATH and now want to add it, see -[our guide on adding Python to PATH](../putting-python-on-path). +### 32-bit vs 64-bit? -Then simply click install, and wait for the install to finish! +Install 64-bit python unless you have reason not to, such as having an old 32-bit computer. Modern PCs ([and all +Windows 11 PCs](https://answers.microsoft.com/en-us/windows/forum/all/does-microsoft-has-32-bit-version-of-windows-11/3bd76840-4e84-4573-8252-71380ef41bf1)) are 64-bit. With 32-bit you may run into memory limits if doing intensive operations (Python will be +limited to using 4GB of memory), and some installed modules may not offer prebuilt +[wheels](https://realpython.com/python-wheels/) for 32 -it, potentially making installs slower or meaning you have to +install build dependencies. -To test your installation, type "cmd" in the windows search bar and select "Command Prompt" to open a terminal (make -sure it's opened _after_ installation has finished) type `python -V`, and press enter. If it outputs your python -version, you've successfully installed Python. (if you didn't add to PATH, you can use [the py -launcher](../installing-and-using-python/#the-py-launcher) to test instead). +If you get an error when installing 64-bit Python, your computer may not support it. To find out if this is the case, +search "About your PC" in the Start Menu and open the Settings page. Then look for the "System Type" option under +"Device Specifications". It should say "64-bit operating system, x64-based processor" if you have support. You need a +64-bit processor and operating system to install 64-bit programs. ## The py Launcher -- cgit v1.2.3 From c2fdf87e9437cfcf4b0fb5b9045881c28ab00199 Mon Sep 17 00:00:00 2001 From: discretegames Date: Mon, 7 Nov 2022 23:10:50 -0800 Subject: re-added venv section to windows guide --- .../windows/installing-and-using-python.md | 41 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md index 23c9e8df..56c3af65 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -138,11 +138,12 @@ Python 4 is [not happening anytime soon](https://builtin.com/software-engineerin ### 32-bit vs 64-bit? -Install 64-bit python unless you have reason not to, such as having an old 32-bit computer. Modern PCs ([and all -Windows 11 PCs](https://answers.microsoft.com/en-us/windows/forum/all/does-microsoft-has-32-bit-version-of-windows-11/3bd76840-4e84-4573-8252-71380ef41bf1)) are 64-bit. With 32-bit you may run into memory limits if doing intensive operations (Python will be -limited to using 4GB of memory), and some installed modules may not offer prebuilt -[wheels](https://realpython.com/python-wheels/) for 32 -it, potentially making installs slower or meaning you have to -install build dependencies. +Install 64-bit python unless you have reason not to, such as having an old 32-bit computer. Modern PCs ([and all Windows +11 +PCs](https://answers.microsoft.com/en-us/windows/forum/all/does-microsoft-has-32-bit-version-of-windows-11/3bd76840-4e84-4573-8252-71380ef41bf1)) +are 64-bit. With 32-bit you may run into memory limits if doing intensive operations (Python will be limited to using +4GB of memory), and some installed modules may not offer prebuilt [wheels](https://realpython.com/python-wheels/) for 32 +-it, potentially making installs slower or meaning you have to install build dependencies. If you get an error when installing 64-bit Python, your computer may not support it. To find out if this is the case, search "About your PC" in the Start Menu and open the Settings page. Then look for the "System Type" option under @@ -155,4 +156,32 @@ dg:TODO ## Virtual Environments -dg:TODO +Virtual environments ("venvs") are a way of giving each of your Python projects their own space to install dependencies +in, so different projects can have different versions of the same dependencies. For example, suppose you are working on +two websites that both use the Python web-framework [Django](https://www.djangoproject.com/download/). One site is older and +requires Django 3.2, and the other is newer and requires Django 4.1. If you install Django globally, no matter if you +install 3.2 or 4.1, one or the or the other of the projects will have the wrong version. But if you make a virtual +environment for each project you can install the required Django version for each separately. + +Virtual environments are not exclusive to Windows, but the commands to use them can differ a bit across operating +systems. Check out the [official docs](https://docs.python.org/3/tutorial/venv.html#creating-virtual-environments) for +more details but there are basically 3 important commands. Run them once `cd`ed into your project folder. + +1. Create a virtual environment: `python -m venv .venv` +2. Activate a virtual environment: `.venv\Scripts\activate` +3. Deactivate a virtual environment: `deactivate` + +(".venv" is a common name for the folder to put virtual environment files in but other names are allowed too.) + +Once you activate a virtual environment, anything you `pip install` will be installed only to that environment. You +should be able to tell when a venv is active because `(.venv)` or similar will appear at the start of terminal +prompts. + +If your editor/IDE has handling for virtual environments, 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). + +The `venv` module used above is built into Python, but [Poetry](https://python-poetry.org/), +[Pipenv](https://pipenv.pypa.io/en/latest/), and [Virtualenv](https://virtualenv.pypa.io/en/latest/) are other popular +tools for managing dependencies and virtual environments. Answers to [this Stack Overflow +question](https://stackoverflow.com/questions/41573587) explain all the confusingly similar names and much more. -- cgit v1.2.3 From 790d076ac2416062466092763b07b22540dee937 Mon Sep 17 00:00:00 2001 From: discretegames Date: Tue, 8 Nov 2022 01:38:18 -0800 Subject: finished py launcher section, finishing Windows guide reorg --- .../windows/installing-and-using-python.md | 71 +++++++++++++++++---- .../content/python-on-windows/py_launcher_1.png | Bin 0 -> 11136 bytes 2 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 pydis_site/static/images/content/python-on-windows/py_launcher_1.png diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md index 56c3af65..04670c03 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -6,8 +6,8 @@ toc: 3 --- 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/) (the main yellow button) using the default options, except -making sure to check the "Add python.exe to PATH" checkbox. Getting Python from the [Microsoft +[python.org Downloads page](https://www.python.org/downloads/) (the main yellow button) using the default options, +except making sure to check the "Add python.exe to PATH" checkbox. Getting Python from the [Microsoft Store](https://apps.microsoft.com/store/search/python) is _not_ recommended as [it can cause various issues](../microsoft-store). @@ -27,10 +27,10 @@ Follow the steps below to install the latest version of Python on Windows. (The instructions were written with Windows 10 and Python 3.11.0 in mind, but should be nearly or fully identical with Windows 11 or other modern versions of Python.) -> If you want a fresh start, you may want to first uninstall any other versions of Python on your PC, including those from -> the Microsoft Store, if you have any. This can be done in the ["Apps & features" Windows -> settings](/static/images/content/python-on-windows/ms_store_uninstall.png) (type "apps and features" into the Start Menu -> to find it). Though it's fine to have multiple versions of Python installed at once. It can be useful for testing +> If you want a fresh start, you may want to first uninstall any other versions of Python on your PC, including those +> from the Microsoft Store, if you have any. This can be done in the ["Apps & features" Windows +> settings](/static/images/content/python-on-windows/ms_store_uninstall.png) (type "apps and features" into the Start +> Menu to find it). Though it's fine to have multiple versions of Python installed at once. It can be useful for testing > version compatibility or for working on projects made in a certain version. Only uninstall things if you want to. 1. Go to [python.org/downloads](https://www.python.org/downloads) and click the big yellow "Download Python 3.x.x" @@ -70,16 +70,16 @@ and run some code like `print("Hello, World!")`. [![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 `py` or `python` in a new terminal window to open up the Python +Or try the more usual way of running Python by typing `python` in a new terminal window to open up the Python [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop), or use `python somefile.py` to run some -Python file (if `py` runs the wrong version of Python, [see below](#the-py-launcher) for how to change the default). Use -whichever terminal you prefer: Command Prompt, PowerShell, an IDE-integrated terminal, [Windows +Python file. Use whichever terminal you prefer: Command Prompt, PowerShell, an IDE-integrated terminal, [Windows Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701). It just has to be a freshly opened terminal or the commands may not be recognized. [![Testing py and python](/static/images/content/python-on-windows/recommended_install_8.png)](/static/images/content/python-on-windows/recommended_install_8.png) -You can double check what versions of Python and [pip](https://pip.pypa.io/en/stable/) were installed by running `python -V` or `pip -V` in a terminal: +You can double check what versions of Python and [pip](https://pip.pypa.io/en/stable/) were installed by running +`python -V` or `pip -V` in a terminal: [![Checking python and pip versions](/static/images/content/python-on-windows/testing_path_worked_1.png)](/static/images/content/python-on-windows/testing_path_worked_1.png) @@ -152,15 +152,58 @@ search "About your PC" in the Start Menu and open the Settings page. Then look f ## The py Launcher -dg:TODO +By default, when you install Python on Windows from a [python.org installer](https://www.python.org/downloads/windows/), +it comes with the "py launcher". The py launcher is a command line tool you invoke using the `py` command and it helps +you run a specific version of Python when you have multiple versions installed. + +The `py` command is not merely shorthand for the `python` command. They are separate programs as can be seen in the +"Apps & features" Windows settings. Though running either of them with no arguments will start the Python +[REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop). + +The py launcher provides the `py -0` command (or `py --list`) which lists the Python versions you have installed. +`py -0p` does the same but includes the paths to the Python executables. + +For example, on my PC I have Python 3.11 and 3.10 installed, and the py launcher shows it: + +![py launcher list command](/static/images/content/python-on-windows/py_launcher_1.png) + +The versions are ordered from newest to oldest, and the asterisk (`*`) indicates which version running `py` will +currently call by default (3.11 in my case). Exactly which version that is depends on the following requirements, and +may not be the same version you get from running `python` (if you get any). + +> If an exact version is not given to `py`, using the latest version can be overridden by the following, (in +> priority order): +> +> - An active virtual environment/ +> - A [shebang]() line in the script (if present). +> - With a `-2` or `-3` flag and matching PY_PYTHON2 or PY_PYTHON3 environment variable. +> - A PY_PYTHON environment variable. +> - From `[defaults]` in py.ini in your `%LOCALAPPDATA%` folder. +> - From `[defaults]` in py.ini beside py.exe (usually in `C:\Windows`, use `where.exe py` to locate). + +You can give the py launcher an exact version of Python to run (assuming you have it installed) by specifying the major +and minor versions. For example, to invoke Python 3.7, you could run `py -3.7`. You can then pass any arguments on top +of that, for example `py -3.7 myscript.py` to run `myscript.py`, or `py -3.7 -m pip install numpy` to invoke `pip` to +install [NumPy](https://numpy.org/) into Python 3.7. + +If you want can always use `py` instead of `python` and not have any Python versions on the Windows Path at all (check +out [this guide](<(../putting-python-on-path)>) to learn about the Windows Path). Though, once in a while third party +software may want to invoke `python`, so keeping it on the Path is handy. We recommend having your "main" Python version +on the Path so you can invoke it with `python`, and then using `py -X.Y` whenever you want a different version, e.g. `py -3.10`. + +The official documentation of the `py launcher` can be found +[here](https://docs.python.org/3/using/windows.html#python-launcher-for-windows). + +The py launcher is not available on Unix-based platforms such as macOS, but there is [an unofficial version by Brett +Cannon](https://github.com/brettcannon/python-launcher). ## Virtual Environments Virtual environments ("venvs") are a way of giving each of your Python projects their own space to install dependencies in, so different projects can have different versions of the same dependencies. For example, suppose you are working on -two websites that both use the Python web-framework [Django](https://www.djangoproject.com/download/). One site is older and -requires Django 3.2, and the other is newer and requires Django 4.1. If you install Django globally, no matter if you -install 3.2 or 4.1, one or the or the other of the projects will have the wrong version. But if you make a virtual +two websites that both use the Python web-framework [Django](https://www.djangoproject.com/download/). One site is older +and requires Django 3.2, and the other is newer and requires Django 4.1. If you install Django globally, no matter if +you install 3.2 or 4.1, one or the or the other of the projects will have the wrong version. But if you make a virtual environment for each project you can install the required Django version for each separately. Virtual environments are not exclusive to Windows, but the commands to use them can differ a bit across operating diff --git a/pydis_site/static/images/content/python-on-windows/py_launcher_1.png b/pydis_site/static/images/content/python-on-windows/py_launcher_1.png new file mode 100644 index 00000000..d4dfab84 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/py_launcher_1.png differ -- cgit v1.2.3 From ee5e1ba623c05f26436ddc08ea46fcd26ddbdd55 Mon Sep 17 00:00:00 2001 From: discretegames Date: Tue, 8 Nov 2022 03:18:27 -0800 Subject: Added WSL2 section to windows guide; other tweaks --- .../windows/installing-and-using-python.md | 11 ++++--- .../python-guides/windows/microsoft-store.md | 4 +-- .../python-guides/windows/unix-env-on-windows.md | 36 +++++++++++++++++----- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md index 04670c03..86a2e571 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -65,8 +65,8 @@ Windows 11 or other modern versions of Python.) ### Checking that it Worked -To test that installing Python worked, you can do what it suggests and search "python" on the Start Menu to find the Python console app -and run some code like `print("Hello, World!")`. +To test that installing Python worked, you can do what it suggests and search "python" on the Start Menu to find the +Python console app and run some code like `print("Hello, World!")`. [![Testing Python console](/static/images/content/python-on-windows/recommended_install_7.png)](/static/images/content/python-on-windows/recommended_install_7.png) @@ -189,13 +189,14 @@ install [NumPy](https://numpy.org/) into Python 3.7. If you want can always use `py` instead of `python` and not have any Python versions on the Windows Path at all (check out [this guide](<(../putting-python-on-path)>) to learn about the Windows Path). Though, once in a while third party software may want to invoke `python`, so keeping it on the Path is handy. We recommend having your "main" Python version -on the Path so you can invoke it with `python`, and then using `py -X.Y` whenever you want a different version, e.g. `py -3.10`. +on the Path so you can invoke it with `python`, and then using `py -X.Y` whenever you want a different version, e.g. +`py -3.7`. The official documentation of the `py launcher` can be found [here](https://docs.python.org/3/using/windows.html#python-launcher-for-windows). -The py launcher is not available on Unix-based platforms such as macOS, but there is [an unofficial version by Brett -Cannon](https://github.com/brettcannon/python-launcher). +The py launcher is not available on GNU/Linux-based platforms such as macOS, but there is [an unofficial version by +Brett Cannon](https://github.com/brettcannon/python-launcher). ## Virtual Environments diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md index 9620c09f..89f11787 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md @@ -12,8 +12,8 @@ Store](https://apps.microsoft.com/store/search/python) as an alternative to usin python.org](https://www.python.org/downloads). **We recommend you install Python on Windows using the [full installer from python.org](https://www.python.org/downloads), and not from the Microsoft store wherever possible!** -You can follow [this guide to install Python from python.org](../installing-and-using-python) and more Python Windows releases -can be found [here](https://www.python.org/downloads/windows). +You can follow [this guide to install Python from python.org](../installing-and-using-python) and more Python Windows +releases can be found [here](https://www.python.org/downloads/windows). Here are some common issues with using Python from the Microsoft Store: diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md b/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md index 47f2138e..a17de183 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md @@ -1,6 +1,6 @@ --- -title: Setting up a Unix-Style Python Environment on Windows -description: How to setup a Unix-style Python environment ready to start coding in +title: Setting up a Unix-Style Python Environment +description: How to setup a Unix-style Python environment on Windows ready to start coding in icon: fab fa-windows --- @@ -28,11 +28,11 @@ simpler interface. Other editors we recommend can be found [here](https://python ## Installing Git Bash -Git is a command line program that helps you keep track of changes to your code, among other things. Many developers use -it, and while you may not need it right away, it is useful to install it because it comes with Git Bash. On the "Select -Components" screen, no settings need to be changed. The next screen will ask what text editor you want to use with Git. -Vim is the default choice, though Vim is widely considered difficult to learn, so you may choose to select Notepad++ or -whichever text editor you may have installed previously. +[Git](https://git-scm.com/downloads) is a command line program that helps you keep track of changes to your code, among +other things. Many developers use it, and while you may not need it right away, it is useful to install it because it +comes with Git Bash. On the "Select Components" screen, no settings need to be changed. The next screen will ask what +text editor you want to use with Git. Vim is the default choice, though Vim is widely considered difficult to learn, so +you may choose to select Notepad++ or whichever text editor you may have installed previously. For all remaining screens in the installation, the default selections are fine. @@ -69,4 +69,24 @@ desktop, `cd /c/Users/YourUsername/Desktop` will take you there. Otherwise if yo explorer, you can right click anywhere in the white space of the file explorer window (not on top of a file) and select "Git Bash Here". Once you're there, type `python hello.py`, and the program will run. - +## WSL + +[WSL (Windows Subsystem for Linux)](https://learn.microsoft.com/en-us/windows/wsl/about) is another increasingly common +way to set up a GNU/Linux-style environment on Windows. It effectively emulates a Linux distribution on Windows, +complete with command line utilities, that you can use alongside your normal Windows programs. (Technically WSL is a +[compatibility layer](https://en.wikipedia.org/wiki/Compatibility_layer), not en emulator.) + +To set up WSL, check out [this installation guide from +Microsoft](https://learn.microsoft.com/en-us/windows/wsl/install). They also have an +[FAQ](https://learn.microsoft.com/en-us/windows/wsl/faq) and a [best practices for using WSL in a development +environment](https://learn.microsoft.com/en-us/windows/wsl/setup/environment). The +[part](https://learn.microsoft.com/en-us/windows/wsl/setup/environment#set-up-windows-terminal) about getting [Windows +Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701) is particularly good advice as it lets +you use one app for all your terminals. + +Also check out these guide for using WSL [with VSCode](https://code.visualstudio.com/docs/remote/wsl) and [with +PyCharm](https://www.jetbrains.com/help/pycharm/using-wsl-as-a-remote-interpreter.html). + +(You may have heard of WSL2 specifically. That is now the default and +[recommended](https://learn.microsoft.com/en-us/windows/wsl/compare-versions) version. If someone says "WSL" they're +probably talking about WSL2.) -- cgit v1.2.3 From c7f37e9be5244a15bc35451e34975761b472fc54 Mon Sep 17 00:00:00 2001 From: discretegames Date: Tue, 8 Nov 2022 05:01:40 -0800 Subject: Proofread windows guides and added image links everywhere --- .../windows/installing-and-using-python.md | 87 +++++++++-------- .../python-guides/windows/microsoft-store.md | 12 ++- .../windows/putting-python-on-path.md | 108 +++++++++++---------- .../python-guides/windows/unix-env-on-windows.md | 2 +- .../content/python-on-windows/py_launcher.png | Bin 0 -> 11136 bytes .../content/python-on-windows/py_launcher_1.png | Bin 11136 -> 0 bytes 6 files changed, 111 insertions(+), 98 deletions(-) create mode 100644 pydis_site/static/images/content/python-on-windows/py_launcher.png delete mode 100644 pydis_site/static/images/content/python-on-windows/py_launcher_1.png diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md index 86a2e571..f2ad0a2f 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -6,7 +6,7 @@ toc: 3 --- 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/) (the main yellow button) using the default options, +[python.org Downloads page](https://www.python.org/downloads/) (hit 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 Store](https://apps.microsoft.com/store/search/python) is _not_ recommended as [it can cause various issues](../microsoft-store). @@ -17,12 +17,12 @@ finally wraps up by explaining some common Windows-specific Python usage, namely and how to work with [virtual environments](#virtual-environments). You may also want to check out our guides on [Common Issues Using Python on Windows](../common-issues), [Adding Python -to the Windows Path](../putting-python-on-path.md), and Setting up a [Unix-Style Environment on +to the Windows Path](../putting-python-on-path.md), and [Setting up a Unix-Style Environment on Windows](../unix-env-on-windows.md). ## Recommended Install -Follow the steps below to install the latest version of Python on Windows. +Follow the five steps below to install the latest version of Python on Windows. (The instructions were written with Windows 10 and Python 3.11.0 in mind, but should be nearly or fully identical with Windows 11 or other modern versions of Python.) @@ -42,12 +42,13 @@ Windows 11 or other modern versions of Python.) [![Step 1](/static/images/content/python-on-windows/recommended_install_1.png)](/static/images/content/python-on-windows/recommended_install_1.png) -2. When it finishes downloading, click the file in your browser or find it in your Downloads folder and double-click it to start the installer. +2. When it finishes downloading, click the file in your browser or find it in your Downloads folder and double-click it + to start the installer. [![Step 2](/static/images/content/python-on-windows/recommended_install_2.png)](/static/images/content/python-on-windows/recommended_install_2.png) 3. Check the "Add python.exe to PATH" checkbox (the text may differ slightly depending on your installer). This will - make it so the command line can recognize commands like `python` and `pip`. (Read [this + make it so terminals can recognize commands like `python` and `pip`. (Read [this guide](../putting-python-on-path) to learn more.) [![Step 3](/static/images/content/python-on-windows/recommended_install_3.png)](/static/images/content/python-on-windows/recommended_install_3.png) @@ -57,8 +58,9 @@ Windows 11 or other modern versions of Python.) [![Step 4](/static/images/content/python-on-windows/recommended_install_4.png)](/static/images/content/python-on-windows/recommended_install_4.png) -5. It will take a minute to install and then (hopefully) say "Setup was successful". Congrats, you just installed - Python! You can close the installer. +5. It will take a minute to install and then (hopefully) say "Setup was successful". + + Congrats! You just installed Python! You can close the installer. [![Step 5 A](/static/images/content/python-on-windows/recommended_install_5.png)](/static/images/content/python-on-windows/recommended_install_5.png) [![Step 5 B](/static/images/content/python-on-windows/recommended_install_6.png)](/static/images/content/python-on-windows/recommended_install_6.png) @@ -72,9 +74,9 @@ Python console app and run some code like `print("Hello, World!")`. Or try the more usual way of running Python by typing `python` in a new terminal window to open up the Python [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop), or use `python somefile.py` to run some -Python file. Use whichever terminal you prefer: Command Prompt, PowerShell, an IDE-integrated terminal, [Windows -Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701). It just has to be a freshly opened -terminal or the commands may not be recognized. +Python file. You can use whichever terminal you prefer: Command Prompt, PowerShell, an IDE-integrated terminal, [Windows +Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701), etc. It just has to be a freshly +opened terminal or the commands may not be recognized. [![Testing py and python](/static/images/content/python-on-windows/recommended_install_8.png)](/static/images/content/python-on-windows/recommended_install_8.png) @@ -96,23 +98,23 @@ is a great starting point. At [python.org/downloads/windows](https://www.python.org/downloads/windows/) there are many different Windows Python installer options available. A link to the latest release page is listed at the top, for example [the Python 3.11.0 -release page](https://www.python.org/downloads/release/python-3110/) has info about new features with downloads at the -bottom. Back on the list of all Windows releases, pre-releases are on the right if you want to try cutting-edge (and -possibly unstable) versions of Python, and stables releases are on the left, all the way back to Python 2.0.1 from 2001. -Some minor versions may not have installers available. +release page](https://www.python.org/downloads/release/python-3110/) has info about the new 3.11 features, with +downloads at the bottom. Back on the list of all Windows releases, pre-releases are on the right if you want to try +cutting-edge (and possibly unstable) versions of Python, and stables releases are on the left, all the way back to +Python 2.0.1 from 2001. Some minor release versions may not have installers available. -You should usually select the "Windows installer" option instead of the "Windows embeddable package". Check out [the -official docs on Using Python on Windows](https://docs.python.org/3/using/windows.html) for more details on other ways -to install Python on Windows. +You should usually select the "Windows installer" option instead of the "Windows embeddable package" when picking what +to get. Check out [the official documentation](https://docs.python.org/3/using/windows.html) for more +details on installing and using Python on Windows. ### Which Version? Current Python versions follow [the form `3.minor.micro`](https://peps.python.org/pep-0440/#final-releases) (similar to [semantic versioning](https://semver.org/)), for example [3.11.0](https://www.python.org/downloads/release/python-3110/). "3" is the major number and not about to change. Minor -releases happen yearly and provide new features and breaking changes, whilst micro releases are more common and only -include bug/security fixes. When people say "Python 3" they aren't necessarily specifying a minor or micro version, but -you can assume they mean the latest ones. +releases happen [yearly](https://endoflife.date/python) and provide new features and breaking changes, whilst micro +releases are more common and only include bug/security fixes. When people say "Python 3" they they aren't necessarily +specifying a minor or micro version, but you can often assume they mean the latest ones. Installing the latest minor version will give you access to Python's newest features. However, some packages may not support the newest versions straight away, so installing the second latest (for example, installing 3.10 when 3.11 is @@ -120,12 +122,13 @@ the latest) will help you avoid those issues. If you find you want some newer fe your current version, you can always install another version as well. You should generally always install the newest micro version, although some may not provide an installer, in which case -you should find the newest that does. +you should find the newest one that does. ### What about Python 2 and 4? -Python 2 should not be used unless you are absolutely required to use it for legacy code or school. [It was officially -sunset January 1, 2020:](https://www.python.org/doc/sunset-python-2) +Python 2 should not be used unless you are absolutely required to for legacy code or school. + +[It was officially sunset January 1, 2020:](https://www.python.org/doc/sunset-python-2) > As of January 1st, 2020 no new bug reports, fixes, or changes will be made to Python 2, and Python 2 is no longer > supported. @@ -138,15 +141,15 @@ Python 4 is [not happening anytime soon](https://builtin.com/software-engineerin ### 32-bit vs 64-bit? -Install 64-bit python unless you have reason not to, such as having an old 32-bit computer. Modern PCs ([and all Windows +Install 64-bit Python unless you have reason not to, such as having an old 32-bit computer. Modern PCs ([and all Windows 11 PCs](https://answers.microsoft.com/en-us/windows/forum/all/does-microsoft-has-32-bit-version-of-windows-11/3bd76840-4e84-4573-8252-71380ef41bf1)) are 64-bit. With 32-bit you may run into memory limits if doing intensive operations (Python will be limited to using -4GB of memory), and some installed modules may not offer prebuilt [wheels](https://realpython.com/python-wheels/) for 32 --it, potentially making installs slower or meaning you have to install build dependencies. +4GB of memory), and some installed modules may not offer prebuilt [wheels](https://realpython.com/python-wheels/) for +32-bit, potentially making installs slower or meaning you have to install build dependencies. If you get an error when installing 64-bit Python, your computer may not support it. To find out if this is the case, -search "About your PC" in the Start Menu and open the Settings page. Then look for the "System Type" option under +search "About your PC" in the Start Menu and open the settings page. Then look for the "System Type" option under "Device Specifications". It should say "64-bit operating system, x64-based processor" if you have support. You need a 64-bit processor and operating system to install 64-bit programs. @@ -156,7 +159,7 @@ By default, when you install Python on Windows from a [python.org installer](htt it comes with the "py launcher". The py launcher is a command line tool you invoke using the `py` command and it helps you run a specific version of Python when you have multiple versions installed. -The `py` command is not merely shorthand for the `python` command. They are separate programs as can be seen in the +The `py` command is not mere shorthand for the `python` command. They are separate programs as can be seen in the "Apps & features" Windows settings. Though running either of them with no arguments will start the Python [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop). @@ -165,16 +168,16 @@ The py launcher provides the `py -0` command (or `py --list`) which lists the Py For example, on my PC I have Python 3.11 and 3.10 installed, and the py launcher shows it: -![py launcher list command](/static/images/content/python-on-windows/py_launcher_1.png) +[![py launcher list command](/static/images/content/python-on-windows/py_launcher.png)](/static/images/content/python-on-windows/py_launcher.png) -The versions are ordered from newest to oldest, and the asterisk (`*`) indicates which version running `py` will -currently call by default (3.11 in my case). Exactly which version that is depends on the following requirements, and -may not be the same version you get from running `python` (if you get any). +The versions are ordered from newest to oldest, and the asterisk (`*`) indicates which version currently running `py` +will call by default (3.11 in my case). Exactly which version that is depends on the following requirements, and may not +be the same version you get when running `python` (if you get any). -> If an exact version is not given to `py`, using the latest version can be overridden by the following, (in -> priority order): +> If an exact version is not given to `py`, the latest is used unless overridden by the following, (in priority +> order): > -> - An active virtual environment/ +> - An active virtual environment. > - A [shebang]() line in the script (if present). > - With a `-2` or `-3` flag and matching PY_PYTHON2 or PY_PYTHON3 environment variable. > - A PY_PYTHON environment variable. @@ -193,7 +196,8 @@ on the Path so you can invoke it with `python`, and then using `py -X.Y` wheneve `py -3.7`. The official documentation of the `py launcher` can be found -[here](https://docs.python.org/3/using/windows.html#python-launcher-for-windows). +[here](https://docs.python.org/3/using/windows.html#python-launcher-for-windows). Use `py --help` to show help on the +command line. The py launcher is not available on GNU/Linux-based platforms such as macOS, but there is [an unofficial version by Brett Cannon](https://github.com/brettcannon/python-launcher). @@ -208,8 +212,9 @@ you install 3.2 or 4.1, one or the or the other of the projects will have the wr environment for each project you can install the required Django version for each separately. Virtual environments are not exclusive to Windows, but the commands to use them can differ a bit across operating -systems. Check out the [official docs](https://docs.python.org/3/tutorial/venv.html#creating-virtual-environments) for -more details but there are basically 3 important commands. Run them once `cd`ed into your project folder. +systems. Check out the [official docs](https://docs.python.org/3/tutorial/venv.html#creating-virtual-environments) and +the builtin [venv](https://docs.python.org/3/library/venv.html) module for more details, but there are basically 3 +important venv commands. Run them once you `cd` into your project folder. 1. Create a virtual environment: `python -m venv .venv` 2. Activate a virtual environment: `.venv\Scripts\activate` @@ -222,10 +227,10 @@ should be able to tell when a venv is active because `(.venv)` or similar will a prompts. If your editor/IDE has handling for virtual environments, 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). +[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 is built into Python, but [Poetry](https://python-poetry.org/), +The `venv` module used above comes with Python, but [Poetry](https://python-poetry.org/), [Pipenv](https://pipenv.pypa.io/en/latest/), and [Virtualenv](https://virtualenv.pypa.io/en/latest/) are other popular tools for managing dependencies and virtual environments. Answers to [this Stack Overflow question](https://stackoverflow.com/questions/41573587) explain all the confusingly similar names and much more. diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md index 89f11787..c7583714 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md @@ -4,15 +4,15 @@ description: The drawbacks of installing the Microsoft Store versions of Python icon: fab fa-windows --- -[](/static/images/content/python-on-windows/ms_store_drake.png) Microsoft provides versions of Python for Windows [on the Microsoft -Store](https://apps.microsoft.com/store/search/python) as an alternative to using the [full installer from -python.org](https://www.python.org/downloads). **We recommend you install Python on Windows using the [full installer +Store](https://apps.microsoft.com/store/search/python) as an alternative to using the installer from +[python.org](https://www.python.org). **We recommend you install Python on Windows using the [full installer from python.org](https://www.python.org/downloads), and not from the Microsoft store wherever possible!** -You can follow [this guide to install Python from python.org](../installing-and-using-python) and more Python Windows +You can follow [this guide](../installing-and-using-python) to install Python from python.org and more Python Windows releases can be found [here](https://www.python.org/downloads/windows). Here are some common issues with using Python from the Microsoft Store: @@ -44,6 +44,8 @@ Here are some common issues with using Python from the Microsoft Store: You can find the path of the executable for a version of Python by running `import sys; print(sys.executable)` in it. + You can learn more about the Windows Path in [this guide](../putting-python-on-path). + - ##### Confusing app execution alias behaviour Typing `python` into a terminal when it is not already installed or not properly on Path may open up the Microsoft @@ -68,4 +70,4 @@ If you have the Microsoft Store version of Python and want to uninstall it, you to open up the "Apps & features" settings and filter by "python". The Python app that has a console in the icon and "Python Software Foundation" under the name is the Microsoft Store one. Click it and hit Uninstall. -![Which version is which when uninstalling Python](/static/images/content/python-on-windows/ms_store_uninstall.png) +[![Which version is which when uninstalling Python](/static/images/content/python-on-windows/ms_store_uninstall.png)](/static/images/content/python-on-windows/ms_store_uninstall.png) 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 3c8face0..e991d485 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 @@ -12,7 +12,7 @@ recommended way](../installing-and-using-python)) but you're still getting error 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/) +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#confusing-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 @@ -22,13 +22,13 @@ The Path (or PATH) environment variable is what Windows uses to locate executabl you type a command name in your terminal, like `python` or `pip`, the terminal looks for a program of 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: +The [python.org 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: -![Add Python to path installer checkbox.](/static/images/content/python-on-windows/installer_path_checkbox.png) +[![Add Python to path installer checkbox.](/static/images/content/python-on-windows/installer_path_checkbox.png)](/static/images/content/python-on-windows/installer_path_checkbox.png) 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, +[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. @@ -36,37 +36,37 @@ method](#advanced-method-manually-edit-the-path) that explains how to edit the P 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`). +[python.org](https://www.python.org/downloads/windows/), or it may still be in your Downloads folder (it's a file named +something 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. - ![Step 1](/static/images/content/python-on-windows/safe_path_method_1.png) + [![Step 1](/static/images/content/python-on-windows/safe_path_method_1.png)](/static/images/content/python-on-windows/safe_path_method_1.png) 2. Select "Modify". (If you don't see the "Modify/Repair/Uninstall" screen then you likely have the wrong installer.) - ![Step 2](/static/images/content/python-on-windows/safe_path_method_2.png) + [![Step 2](/static/images/content/python-on-windows/safe_path_method_2.png)](/static/images/content/python-on-windows/safe_path_method_2.png) 3. Hit "Next" to move past the "Optional Features" screen. - ![Step 3](/static/images/content/python-on-windows/safe_path_method_3.png) + [![Step 3](/static/images/content/python-on-windows/safe_path_method_3.png)](/static/images/content/python-on-windows/safe_path_method_3.png) -4. Check "Add Python to environment variables" on the "Advanced Options" screen. +4. Check the "Add Python to environment variables" checkbox on the "Advanced Options" screen. - ![Step 4](/static/images/content/python-on-windows/safe_path_method_4.png) + [![Step 4](/static/images/content/python-on-windows/safe_path_method_4.png)](/static/images/content/python-on-windows/safe_path_method_4.png) 5. Hit install! - ![Step 5](/static/images/content/python-on-windows/safe_path_method_5.png) + [![Step 5](/static/images/content/python-on-windows/safe_path_method_5.png)](/static/images/content/python-on-windows/safe_path_method_5.png) -Then, after a moment, it should say "Modify was successful" and you can close the installer, and Python should now be on +Then, after a moment, it should say "Modify was successful" and you can close the installer. 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.) +(These steps are for the Python 3.11 and 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 +will still need to locate the installer exe at step 5 if it's not already in Downloads.) ### Verifying your changes @@ -86,12 +86,12 @@ pip -V and you should see the versions of Python and pip that you just added to Path: -![Checking Python and pip versions.](/static/images/content/python-on-windows/testing_path_worked_1.png) +[![Checking Python and pip versions.](/static/images/content/python-on-windows/testing_path_worked_1.png)](/static/images/content/python-on-windows/testing_path_worked_1.png) Running `Get-Command python` in PowerShell, or `where python` in Command Prompt, you can see where that terminal is finding the `python.exe` it would run when a `python` command is given: -![Get-Command/where Python.](/static/images/content/python-on-windows/testing_path_worked_2.png) +[![Get-Command/where Python.](/static/images/content/python-on-windows/testing_path_worked_2.png)](/static/images/content/python-on-windows/testing_path_worked_2.png) (`where` in fact lists all the Pythons it finds, even the dummy [app execution alias](../microsoft-store#confusing-app-execution-alias-behaviour) one that opens the Microsoft Store.) @@ -105,12 +105,12 @@ import sys; print(sys.executable); exit(); to see that the exact executable that is currently running Python is what you expect: -![Checking Python executable.](/static/images/content/python-on-windows/testing_path_worked_3.png) +[![Checking Python executable.](/static/images/content/python-on-windows/testing_path_worked_3.png)](/static/images/content/python-on-windows/testing_path_worked_3.png) Of course your username will probably not be "r", and your executable path may differ from `C:\Users\\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 +version you have. The last folder will normally 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](https://pypi.org/project/pyinstaller/) it) now work for you! Hopefully things are indeed working, however, it is possible that, due to having multiple Python versions, or other @@ -133,7 +133,7 @@ But, as explained [here](https://superuser.com/a/878382), when actually used, th Path, forming one long list. So, how it works is whenever you type a command like `python` into a terminal, the terminal looks for a matching -runnable file like `python.exe` (or [`python.bat`](https://en.wikipedia.org/wiki/Batch_file)) in each of the folders +runnable file like `python.exe` ([or `python.bat`](https://en.wikipedia.org/wiki/Batch_file)) in each of the folders listed in the Path, starting with the System Path (top to bottom), and then the User Path (top to bottom). It stops searching on the first one it finds and runs that program with the command line arguments you may have given it, hence (hopefully) running Python from an installed `python.exe`. @@ -153,90 +153,96 @@ Again, the Path lookup order is: ### Adding Python to your Path -Here the common case of adding Python to the Windows Path is detailed. Though knowing how to manually modify the Path is -handy beyond that whenever you need to change or debug which programs run on the command line. (The less customizable -but [safer method is above](#safe-method-let-the-installer-add-python-to-path) if you missed it.) +Here the common case of adding Python and the Python Scripts directory to the Windows Path is detailed. Though knowing +how to manually modify the Path is handy beyond just Python for whenever you need to change or debug which programs run +on the command line in Windows. (The less customizable but [safer method is +above](#safe-method-let-the-installer-add-python-to-path) if you missed it.) Follow these steps to add Python to the Path: -1. First, find folder path your Python executable is in. There are a couple ways to do this: +1. First, find the folder path your Python executable is in. There are a few ways to do this: **Way 1**: Run `py -0p` on the command line and copy the folder path of the version you want: - ![Finding exe with py.](/static/images/content/python-on-windows/finding_exe_1.png) + [![Finding exe with py.](/static/images/content/python-on-windows/finding_exe_1.png)](/static/images/content/python-on-windows/finding_exe_1.png) **Way 2**: Run `import sys; print(sys.executable)` in Python on your PC and copy the folder path it prints out: - ![Finding exe in repl.](/static/images/content/python-on-windows/finding_exe_2.png) + [![Finding exe in repl.](/static/images/content/python-on-windows/finding_exe_2.png)](/static/images/content/python-on-windows/finding_exe_2.png) - Either way I end up with `C:\Users\r\AppData\Local\Programs\Python\Python311\` (no `python.exe` at the end). + **Way 3**: Root around a bit in your `C:\Users\\AppData\Local\Programs\Python` folder or wherever you + installed Python to find the path to the folder that has the `python.exe` in it. + + I end up with `C:\Users\r\AppData\Local\Programs\Python\Python311\` (no `python.exe` at the end). Your path will of course be based on your username (my username is "r") and your version of Python, such as `C:\Users\ducky\AppData\Local\Programs\Python\Python39\` if your username is "ducky" and you're using Python 3.9. - Copy your path, we'll use it in steps 6 and 7. + Copy your path. We'll use it in steps 6 and 7. -2. [This step is optional but helpful to see what's going on.] Copy the folder path from step 1 into the path bar of - Windows File Explorer. In the folder you should be able to see `python.exe`, and in the Scripts subfolder, things +2. [**This step is optional but helpful to see what's going on.**] Copy the folder path from step 1 into the path bar + of Windows File Explorer. In the folder you should be able to see `python.exe`, and in the Scripts subfolder, things like `pip.exe` and `pyinstaller.exe` (if you have it installed). - ![Finding exes in folder.](/static/images/content/python-on-windows/finding_exe_3.png) + [![Finding exes in folder.](/static/images/content/python-on-windows/finding_exe_3.png)](/static/images/content/python-on-windows/finding_exe_3.png) These are the executables we want the command line to be able to find via the Windows Path. 3. Now, type "environment variables" in the Start menu or Start search box and open the "Edit the system environment variables" option. - ![Step 3](/static/images/content/python-on-windows/edit_path_1.png) + [![Step 3](/static/images/content/python-on-windows/edit_path_1.png)](/static/images/content/python-on-windows/edit_path_1.png) 4. Hit the "Environment Variables..." button. - ![Step 4](/static/images/content/python-on-windows/edit_path_2.png) + [![Step 4](/static/images/content/python-on-windows/edit_path_2.png)](/static/images/content/python-on-windows/edit_path_2.png) -5. In a new window you should see two "Path" variables, one under "User variables for <user>" and one under +5. Then in a new window you should see two "Path" variables, one under "User variables for <user>" and one under "System variables". Select one of them (most likely the User Path) and hit the "Edit..." button underneath it. + [![Step 5](/static/images/content/python-on-windows/edit_path_3.png)](/static/images/content/python-on-windows/edit_path_3.png) + I suggest using the User Path (what the screenshots show) for the default installation of Python. In general, only put things on the System Path if they are installed for all users (e.g. in `C:\Program Files` or `C:\`) and you're certain they won't overshadow anything in User Paths. **Remember, the System Path takes precedence over the User Path when commands are looked up.** - ![Step 5](/static/images/content/python-on-windows/edit_path_3.png) - (Don't worry if your variables or Path contents differ a bit from those shown.) -6. The third window that opens is where the Path is actually edited. It shows the ordered list of the folders on the +6. Now a third window opens and this is where the Path is actually edited. It shows the ordered list of the folders on the Path and you can select the entries, edit them, reorder them, make new ones, delete them and so on. (Don't delete any unless you know what you're doing!) We want to add the Python executable path we found in step 1 as a new entry, so click "New" and paste in the path. - ![Step 6](/static/images/content/python-on-windows/edit_path_4.png) + [![Step 6](/static/images/content/python-on-windows/edit_path_4.png)](/static/images/content/python-on-windows/edit_path_4.png) 7. We also need to add the Python Scripts directory to the Path to have commands like `pip` and `pyinstaller` work. So hit "New" and paste in the Python executable path again, and type "Scripts" after it. - ![Step 7](/static/images/content/python-on-windows/edit_path_5.png) + [![Step 7](/static/images/content/python-on-windows/edit_path_5.png)](/static/images/content/python-on-windows/edit_path_5.png) + + (It doesn't matter whether or not they have trailing backslashes.) 8. Finally, select each of the paths you just added in turn and move them to the very top of the list using the "Move Up" button. (Their relative order should not matter.) - ![Step 8](/static/images/content/python-on-windows/edit_path_6.png) + [![Step 8](/static/images/content/python-on-windows/edit_path_6.png)](/static/images/content/python-on-windows/edit_path_6.png) This step may not be strictly necessary, but remember that command lookup happens in order from top to bottom. - Python is often bundled with other software that may end up on the Path, so there's there could be another + Python is often bundled with other software that may end up on the Path, so there could be another `python.exe` in one of of the other folders on the path that gets in the way. (This exact thing has happened to me when I put `C:\Program Files\Inkscape\bin` on my Path, as [Inkscape](https://inkscape.org/) comes with a copy of Python.) - Also, the System Path comes first in command lookup, so to be certain you to may want to go back and check the - System Path (see step 5) and _carefully_ delete any entry that is a Python executable path blocking the one you just - added. Though please, don't delete any Path entries you're aren't sure about! Just in case, for reference, [here are - the important looking System Path entries](/static/images/content/python-on-windows/system_path_important.png) on my - Windows 10 64-bit PC. + > _8.5._ Recall, the System Path comes before the User Path during command lookup, so to be certain you to may want + > to go back and check the "System variables" Path (see step 5) and _carefully_ delete any entry that you're sure is + > a path to a Python executable overshadowing the one you just added. Though please, don't delete any Path entries + > you're aren't certain about! Just in case, for reference, [here are the important looking System Path + > entries](/static/images/content/python-on-windows/system_path_important.png) on my 64-bit Windows 10 PC. 9. Finish by making sure to hit "OK" on each of the thee "Edit environment variable", "Environment Variable", and - "System Properties" windows, and then you're done! + "System Properties" windows, and then you're done! (If you accidentally hit Cancel the changes may not be saved.) - Python and Python Scripts should not be on your Path! **You will need to restart any terminals or editors you have + Python and Python Scripts should now be on your Path! **You will need to restart any terminals or editors you have open before they detect the change.** At this point you can [verify your changes in the same way as detailed above](#verifying-your-changes). Hopefully it diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md b/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md index a17de183..22ca70d1 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/unix-env-on-windows.md @@ -78,7 +78,7 @@ complete with command line utilities, that you can use alongside your normal Win To set up WSL, check out [this installation guide from Microsoft](https://learn.microsoft.com/en-us/windows/wsl/install). They also have an -[FAQ](https://learn.microsoft.com/en-us/windows/wsl/faq) and a [best practices for using WSL in a development +[FAQ](https://learn.microsoft.com/en-us/windows/wsl/faq) and a [best practices guide for using WSL in a development environment](https://learn.microsoft.com/en-us/windows/wsl/setup/environment). The [part](https://learn.microsoft.com/en-us/windows/wsl/setup/environment#set-up-windows-terminal) about getting [Windows Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701) is particularly good advice as it lets diff --git a/pydis_site/static/images/content/python-on-windows/py_launcher.png b/pydis_site/static/images/content/python-on-windows/py_launcher.png new file mode 100644 index 00000000..d4dfab84 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/py_launcher.png differ diff --git a/pydis_site/static/images/content/python-on-windows/py_launcher_1.png b/pydis_site/static/images/content/python-on-windows/py_launcher_1.png deleted file mode 100644 index d4dfab84..00000000 Binary files a/pydis_site/static/images/content/python-on-windows/py_launcher_1.png and /dev/null differ -- cgit v1.2.3 From 529cc5a901b776dafe4c8da88281728d5a75d10e Mon Sep 17 00:00:00 2001 From: discretegames <35741644+discretegames@users.noreply.github.com> Date: Tue, 8 Nov 2022 18:14:47 -0800 Subject: Update pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md Co-authored-by: Amrou Bellalouna <48383734+shtlrs@users.noreply.github.com> --- .../content/resources/guides/python-guides/windows/common-issues.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md index f86d5d48..168b0e56 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -27,7 +27,7 @@ PATH" checkbox on the first page of the installer. See [our guide on adding Pyth 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 get a `ModuleNotFoundError` +### I `pip` installed a package but when running my code I get a `ModuleNotFoundError` - #### Are you actually getting a `ModuleNotFoundError`? -- cgit v1.2.3 From 6d2db8cfa76636571f342152894f2a9ef1c5bc3e Mon Sep 17 00:00:00 2001 From: discretegames <35741644+discretegames@users.noreply.github.com> Date: Tue, 8 Nov 2022 18:15:42 -0800 Subject: Update pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md Co-authored-by: Amrou Bellalouna <48383734+shtlrs@users.noreply.github.com> --- .../content/resources/guides/python-guides/windows/common-issues.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md index 168b0e56..0d0d2a70 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -33,7 +33,7 @@ with `py`. See [this guide](../installing-and-using-python/#the-py-launcher) for If you are using a code editor such as VSCode or PyCharm you may get a squiggly line under your import saying the module couldn't be found, it is possible that this is just an mistake by the editor, so try actually running your - code with to ensure if it actually errors. +so try to actually run your code the way it is to ensure that it actually errors. If your code runs fine, you could try restarting your editor. If you have newly installed a module it may just not have detected it yet. If that doesn't help, you may need to configure your editor to ensure it is looking for the -- cgit v1.2.3 From c6147f9837416271bb0087b424202b8fb684f6c9 Mon Sep 17 00:00:00 2001 From: discretegames <35741644+discretegames@users.noreply.github.com> Date: Tue, 8 Nov 2022 18:17:18 -0800 Subject: Update pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md Co-authored-by: Amrou Bellalouna <48383734+shtlrs@users.noreply.github.com> --- .../content/resources/guides/python-guides/windows/common-issues.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md index 0d0d2a70..2245553b 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -82,7 +82,7 @@ so try to actually run your code the way it is to ensure that it actually errors ##### I installed the module using pip from the command line - > Run `pip -V` and look at the path returned it should be in the form `\Lib\site-packages\pip`. + > Run `pip -V` and look at the path it returned, which should be in the form `\Lib\site-packages\pip`. > > Then put `import sys;print(sys.executable);sys.exit(0);` at the top (above imports!) of your python file, and run > it. The result should be in the form `\python.exe`. -- cgit v1.2.3 From b3406ec60f968e729fd2b2fab53adca71ae92567 Mon Sep 17 00:00:00 2001 From: discretegames Date: Tue, 8 Nov 2022 18:19:26 -0800 Subject: emphasized NOT --- .../content/resources/guides/python-guides/windows/microsoft-store.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md index c7583714..82e8d851 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md @@ -1,5 +1,5 @@ --- -title: Why Not to Install Python from the Microsoft Store +title: Why NOT to Install Python from the Microsoft Store description: The drawbacks of installing the Microsoft Store versions of Python icon: fab fa-windows --- -- cgit v1.2.3 From 885eacb1a24c60a4e08868e49267fede5d8bce66 Mon Sep 17 00:00:00 2001 From: discretegames Date: Tue, 8 Nov 2022 19:24:09 -0800 Subject: added shtlrs Windows guide suggestions --- .../guides/python-guides/windows/common-issues.md | 23 ++++++++++++++------- .../python-on-windows/pycharm_python_path.png | Bin 0 -> 20097 bytes .../content/python-on-windows/venv_prompt.png | Bin 0 -> 1633 bytes 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 pydis_site/static/images/content/python-on-windows/pycharm_python_path.png create mode 100644 pydis_site/static/images/content/python-on-windows/venv_prompt.png diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md index 2245553b..35041dd8 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -32,8 +32,8 @@ with `py`. See [this guide](../installing-and-using-python/#the-py-launcher) for - #### Are you actually getting a `ModuleNotFoundError`? If you are using a code editor such as VSCode or PyCharm you may get a squiggly line under your import saying the - module couldn't be found, it is possible that this is just an mistake by the editor, so try actually running your -so try to actually run your code the way it is to ensure that it actually errors. + module couldn't be found, it is possible that this is just an mistake by the editor, so try to actually run your + code the way it is to ensure that it actually errors. If your code runs fine, you could try restarting your editor. If you have newly installed a module it may just not have detected it yet. If that doesn't help, you may need to configure your editor to ensure it is looking for the @@ -69,7 +69,11 @@ so try to actually run your code the way it is to ensure that it actually errors This is a very common issue. When you install a module from PyPI, you will install it into a single Python environment, the one that the `pip` you invoked is part of. This could be different to the one you are running the - script from if it's using a different Python installation, or a virtual environment. + script from if it's using a different Python installation, or a [virtual environment](../installing-and-using-python/#virtual-environments). + + You can tell when you're in a virtual environment because the name of the venv folder will usually be shown in + parentheses at the start of terminal prompts. You can type `deactivate` to get out of it. + [![Venv terminal prompt.](/static/images/content/python-on-windows/venv_prompt.png)](/static/images/content/python-on-windows/venv_prompt.png) ##### I'm using PyCharm @@ -77,6 +81,10 @@ so try to actually run your code the way it is to ensure that it actually errors > you need to make sure you also run your code through PyCharm. This also applies the other way round, if you want > to use a module in PyCharm you need to install it through PyCharm. > + > You can see the exact path of the current Python interpreter, and thus virtual environment, in PyCharm by hovering + > your mouse over the interpreter info menu on the bottom right: + > [![PyCharm python.exe info.](/static/images/content/python-on-windows/pycharm_python_path.png)](/static/images/content/python-on-windows/pycharm_python_path.png) + > > It's also possible to change PyCharm to use your system environment, see [their guide on configuring your > interpreter](https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html) for more information. @@ -150,10 +158,11 @@ loop](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)), also 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 the normal terminal, not in the Python REPL. It usually has -`>>>` at the start of each line. To exit the REPL, type `exit()` and press enter. You should then be able to run your -commands normally, unless it was the Python App, in which case it will close completely and you'll need to open a -terminal like PowerShell or Command Prompt separately. +General commands like `pip` and `python` should be run in your computer's normal terminal, that is, directly in +something like Command Prompt or PowerShell. _Not_ in the Python REPL, which usually has `>>>` at the start of each +line. To exit the Python REPL, type `exit()` and press enter. You should then be able to run your commands normally, +unless it was the Python App, in which case it will close completely and you'll need to open a normal terminal +separately. ### I tried to uninstall Python by deleting the folder, now it doesn't work and I can't reinstall it! diff --git a/pydis_site/static/images/content/python-on-windows/pycharm_python_path.png b/pydis_site/static/images/content/python-on-windows/pycharm_python_path.png new file mode 100644 index 00000000..9c70bcf7 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/pycharm_python_path.png differ diff --git a/pydis_site/static/images/content/python-on-windows/venv_prompt.png b/pydis_site/static/images/content/python-on-windows/venv_prompt.png new file mode 100644 index 00000000..a2f18087 Binary files /dev/null and b/pydis_site/static/images/content/python-on-windows/venv_prompt.png differ -- cgit v1.2.3 From be31bfd32b868c1ba671091d4bc7f76c28990cd9 Mon Sep 17 00:00:00 2001 From: discretegames Date: Tue, 8 Nov 2022 19:36:15 -0800 Subject: Note about admin needed, and added subheading to Path guide. --- .../guides/python-guides/windows/putting-python-on-path.md | 6 +++--- 1 file changed, 3 insertions(+), 3 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 e991d485..fdb33c9a 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 @@ -120,6 +120,8 @@ will hopefully be able to help.) ## Advanced Method: Manually edit the Path +### About the Path + As mentioned above, the Path (often called "PATH", though it shows up as "Path") is what Windows uses to locate executables needed on the command line. If it's misconfigured, `python` and `pip` commands may not work as expected. @@ -158,7 +160,7 @@ how to manually modify the Path is handy beyond just Python for whenever you nee on the command line in Windows. (The less customizable but [safer method is above](#safe-method-let-the-installer-add-python-to-path) if you missed it.) -Follow these steps to add Python to the Path: +Follow these steps to add Python to the Path. **You will need administrator privileges on your computer.** 1. First, find the folder path your Python executable is in. There are a few ways to do this: @@ -250,5 +252,3 @@ works! (These steps were written with Windows 10 and Python 3.11 in mind, but they should be identical or similar for Windows 11 and other recent versions of Python.) - - -- cgit v1.2.3 From b8bc86cedce0550528b944b79c1f2975eb10658e Mon Sep 17 00:00:00 2001 From: discretegames <35741644+discretegames@users.noreply.github.com> Date: Sat, 12 Nov 2022 17:46:40 -0800 Subject: Update pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md Co-authored-by: wookie184 --- .../guides/python-guides/windows/installing-and-using-python.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md index f2ad0a2f..fe6a4e39 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -34,7 +34,7 @@ Windows 11 or other modern versions of Python.) > version compatibility or for working on projects made in a certain version. Only uninstall things if you want to. 1. Go to [python.org/downloads](https://www.python.org/downloads) and click the big yellow "Download Python 3.x.x" - button near the top of the page. That should start the download of the latest Windows Python installer that best + button near the top of the page. That should start the download of the installer for the latest version that best suits your computer. If you want a different version or it doesn't work for some reason, you can download the -- cgit v1.2.3 From 26f36b25c5bb96d30878eeed266f86ca545b5350 Mon Sep 17 00:00:00 2001 From: discretegames <35741644+discretegames@users.noreply.github.com> Date: Sat, 12 Nov 2022 17:49:25 -0800 Subject: Update pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md Co-authored-by: wookie184 --- .../guides/python-guides/windows/installing-and-using-python.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md index fe6a4e39..b52fdb20 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -54,7 +54,7 @@ Windows 11 or other modern versions of Python.) [![Step 3](/static/images/content/python-on-windows/recommended_install_3.png)](/static/images/content/python-on-windows/recommended_install_3.png) 4. Then click the big "Install Now" button. Aside from adding Python to PATH, the rest of the installer defaults are - usually fine, so there's no need to customize the installation unless you want to. + usually fine, so there's no need to customize the installation unless you have a specific reason to. [![Step 4](/static/images/content/python-on-windows/recommended_install_4.png)](/static/images/content/python-on-windows/recommended_install_4.png) -- cgit v1.2.3 From e3975c95db807e91c5b36e2abde0c45258c90cd8 Mon Sep 17 00:00:00 2001 From: discretegames <35741644+discretegames@users.noreply.github.com> Date: Sat, 12 Nov 2022 17:51:32 -0800 Subject: Update pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md Co-authored-by: wookie184 --- .../guides/python-guides/windows/installing-and-using-python.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md index b52fdb20..7068d33e 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -211,7 +211,7 @@ and requires Django 3.2, and the other is newer and requires Django 4.1. If you you install 3.2 or 4.1, one or the or the other of the projects will have the wrong version. But if you make a virtual environment for each project you can install the required Django version for each separately. -Virtual environments are not exclusive to Windows, but the commands to use them can differ a bit across operating +Virtual environments are not exclusive to Windows, but the commands to use them can differ across operating systems. Check out the [official docs](https://docs.python.org/3/tutorial/venv.html#creating-virtual-environments) and the builtin [venv](https://docs.python.org/3/library/venv.html) module for more details, but there are basically 3 important venv commands. Run them once you `cd` into your project folder. -- cgit v1.2.3 From 0bb9447e5407f7de00add5c93fa90ed2a9f31a17 Mon Sep 17 00:00:00 2001 From: discretegames <35741644+discretegames@users.noreply.github.com> Date: Sat, 12 Nov 2022 17:52:47 -0800 Subject: Update pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md Co-authored-by: wookie184 --- .../content/resources/guides/python-guides/windows/common-issues.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md index 35041dd8..f80c1d29 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -5,7 +5,7 @@ icon: fab fa-windows toc: 3 --- -### When I run `python` in the terminal I get no result, or the Windows Store opens! +### 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 -- cgit v1.2.3 From f612d4c7183c7513080ec035298e495c438a92df Mon Sep 17 00:00:00 2001 From: discretegames <35741644+discretegames@users.noreply.github.com> Date: Sat, 12 Nov 2022 18:01:19 -0800 Subject: Update pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md Co-authored-by: wookie184 --- .../guides/python-guides/windows/installing-and-using-python.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md index 7068d33e..f6e9fed2 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -73,7 +73,7 @@ Python console app and run some code like `print("Hello, World!")`. [![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 -[REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop), or use `python somefile.py` to run some +[REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop), or use `python somefile.py` to run a Python file. You can use whichever terminal you prefer: Command Prompt, PowerShell, an IDE-integrated terminal, [Windows Terminal](https://apps.microsoft.com/store/detail/windows-terminal/9N0DX20HK701), etc. It just has to be a freshly opened terminal or the commands may not be recognized. -- cgit v1.2.3 From 236963db16bfd792f0054fb0eeda62d371c24ee0 Mon Sep 17 00:00:00 2001 From: discretegames <35741644+discretegames@users.noreply.github.com> Date: Sat, 12 Nov 2022 18:26:12 -0800 Subject: Update pydis_site/apps/content/resources/guides/python-guides/windows/putting-python-on-path.md Co-authored-by: wookie184 --- .../resources/guides/python-guides/windows/putting-python-on-path.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fdb33c9a..8b288bf7 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 @@ -115,7 +115,7 @@ installed](https://pypi.org/project/pyinstaller/) 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. (If -you already did that, open a help channel on the [Python Discord server](https://discord.com/invite/python) and someone +you already did that, open a help channel on the [Python Discord server](https://discord.com/invite/python) explaining everything you've tried so far, and someone will hopefully be able to help.) ## Advanced Method: Manually edit the Path -- cgit v1.2.3 From 9b21ec8c702961adc731aee83162f68cd8de65b1 Mon Sep 17 00:00:00 2001 From: discretegames <35741644+discretegames@users.noreply.github.com> Date: Sat, 12 Nov 2022 18:27:51 -0800 Subject: Update pydis_site/apps/content/resources/guides/python-guides/windows/putting-python-on-path.md Co-authored-by: wookie184 --- .../resources/guides/python-guides/windows/putting-python-on-path.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8b288bf7..db833a98 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 @@ -155,7 +155,7 @@ Again, the Path lookup order is: ### Adding Python to your Path -Here the common case of adding Python and the Python Scripts directory to the Windows Path is detailed. Though knowing +Here only the common case of adding Python and the Python Scripts directory to the Windows Path is detailed. However, knowing how to manually modify the Path is handy beyond just Python for whenever you need to change or debug which programs run on the command line in Windows. (The less customizable but [safer method is above](#safe-method-let-the-installer-add-python-to-path) if you missed it.) -- cgit v1.2.3 From db505b41301616cb44ebc85a3891e6c122155edc Mon Sep 17 00:00:00 2001 From: discretegames <35741644+discretegames@users.noreply.github.com> Date: Sat, 12 Nov 2022 18:29:31 -0800 Subject: Update pydis_site/apps/content/resources/guides/python-guides/windows/putting-python-on-path.md Co-authored-by: wookie184 --- .../resources/guides/python-guides/windows/putting-python-on-path.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 db833a98..09c6f9da 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 @@ -202,7 +202,7 @@ Follow these steps to add Python to the Path. **You will need administrator priv [![Step 5](/static/images/content/python-on-windows/edit_path_3.png)](/static/images/content/python-on-windows/edit_path_3.png) - I suggest using the User Path (what the screenshots show) for the default installation of Python. In general, only + You should use the User Path (what the screenshots show) for the default installation of Python. In general, only put things on the System Path if they are installed for all users (e.g. in `C:\Program Files` or `C:\`) and you're certain they won't overshadow anything in User Paths. **Remember, the System Path takes precedence over the User Path when commands are looked up.** -- cgit v1.2.3 From d065f2e71b5741e0a65ce33a1093685f9c6d9501 Mon Sep 17 00:00:00 2001 From: discretegames Date: Sat, 12 Nov 2022 18:32:22 -0800 Subject: Added some of wookies Windows guide review suggestions --- .../resources/guides/python-guides/windows/common-issues.md | 2 +- .../python-guides/windows/installing-and-using-python.md | 10 +++++----- .../resources/guides/python-guides/windows/microsoft-store.md | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md index 35041dd8..6ab3e3c5 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -135,7 +135,7 @@ common causes for this are: To check if this is the case, type `pip -V`. If the path output includes something like `PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0`, you are using Python from the Microsoft Store. To fix this you will either have to use the full path to the scripts you want to use, or [uninstall the - Microsoft Store Python](/static/images/content/python-on-windows/ms_store_uninstall.png) and [install Python + Microsoft Store Python](../miscrosoft-store/#uninstalling) and [install Python properly](../installing-and-using-python) with a [python.org installer](https://www.python.org/downloads). - You manually modified your PATH Environment Variable incorrectly diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md index f2ad0a2f..4bbaf4a3 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -6,7 +6,7 @@ toc: 3 --- 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/) (hit the big yellow button) using the default options, +[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 Store](https://apps.microsoft.com/store/search/python) is _not_ recommended as [it can cause various issues](../microsoft-store). @@ -27,8 +27,8 @@ Follow the five steps below to install the latest version of Python on Windows. (The instructions were written with Windows 10 and Python 3.11.0 in mind, but should be nearly or fully identical with Windows 11 or other modern versions of Python.) -> If you want a fresh start, you may want to first uninstall any other versions of Python on your PC, including those -> from the Microsoft Store, if you have any. This can be done in the ["Apps & features" Windows +> If you want a fresh start, you should check for and uninstall any versions of Python already on your PC, including +> those from the Microsoft Store. This can be done in the ["Apps & features" Windows > settings](/static/images/content/python-on-windows/ms_store_uninstall.png) (type "apps and features" into the Start > Menu to find it). Though it's fine to have multiple versions of Python installed at once. It can be useful for testing > version compatibility or for working on projects made in a certain version. Only uninstall things if you want to. @@ -208,8 +208,8 @@ Virtual environments ("venvs") are a way of giving each of your Python projects in, so different projects can have different versions of the same dependencies. For example, suppose you are working on two websites that both use the Python web-framework [Django](https://www.djangoproject.com/download/). One site is older and requires Django 3.2, and the other is newer and requires Django 4.1. If you install Django globally, no matter if -you install 3.2 or 4.1, one or the or the other of the projects will have the wrong version. But if you make a virtual -environment for each project you can install the required Django version for each separately. +you install 3.2 or 4.1, one or the or the other of the projects will have the wrong version. If instead you make a +virtual environment for each project, you can install the required Django version for each separately. Virtual environments are not exclusive to Windows, but the commands to use them can differ a bit across operating systems. Check out the [official docs](https://docs.python.org/3/tutorial/venv.html#creating-virtual-environments) and diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md index 82e8d851..8b496779 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md @@ -12,6 +12,10 @@ Store](https://apps.microsoft.com/store/search/python) as an alternative to usin [python.org](https://www.python.org). **We recommend you install Python on Windows using the [full installer from python.org](https://www.python.org/downloads), and not from the Microsoft store wherever possible!** +Installing Python from [python.org](https://www.python.org) does not normally require administrator privileges, but if +for whatever reason don't have permission to install it, don't feel bad if you get the Microsoft Store version instead. +Better some Python than no Python. + You can follow [this guide](../installing-and-using-python) to install Python from python.org and more Python Windows releases can be found [here](https://www.python.org/downloads/windows). @@ -66,6 +70,8 @@ Here are some common issues with using Python from the Microsoft Store: latest Python version you can but if you ever need earlier than 3.7 for testing or for working on older code, the store can't help. +## Uninstalling + If you have the Microsoft Store version of Python and want to uninstall it, you can search "uninstall" in the Start menu to open up the "Apps & features" settings and filter by "python". The Python app that has a console in the icon and "Python Software Foundation" under the name is the Microsoft Store one. Click it and hit Uninstall. -- cgit v1.2.3 From c3bb0b5b51eae840a34a70443c5dcc5ffa97f23a Mon Sep 17 00:00:00 2001 From: discretegames Date: Sat, 12 Nov 2022 18:37:38 -0800 Subject: NOT back to Not and wrapped things to 120chars --- .../guides/python-guides/windows/common-issues.md | 3 ++- .../guides/python-guides/windows/microsoft-store.md | 2 +- .../python-guides/windows/putting-python-on-path.md | 16 ++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md index 878ff20c..65633609 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -90,7 +90,8 @@ with `py`. See [this guide](../installing-and-using-python/#the-py-launcher) for ##### I installed the module using pip from the command line - > Run `pip -V` and look at the path it returned, which should be in the form `\Lib\site-packages\pip`. + > Run `pip -V` and look at the path it returned, which should be in the form + > `\Lib\site-packages\pip`. > > Then put `import sys;print(sys.executable);sys.exit(0);` at the top (above imports!) of your python file, and run > it. The result should be in the form `\python.exe`. diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md index 8b496779..0a752fb3 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/microsoft-store.md @@ -1,5 +1,5 @@ --- -title: Why NOT to Install Python from the Microsoft Store +title: Why Not to Install Python from the Microsoft Store description: The drawbacks of installing the Microsoft Store versions of Python icon: fab fa-windows --- 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 09c6f9da..18a3d787 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 @@ -115,8 +115,8 @@ installed](https://pypi.org/project/pyinstaller/) 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. (If -you already did that, open a help channel on the [Python Discord server](https://discord.com/invite/python) explaining everything you've tried so far, and someone -will hopefully be able to help.) +you already did that, open a help channel on the [Python Discord server](https://discord.com/invite/python) explaining +everything you've tried so far, and someone will hopefully be able to help.) ## Advanced Method: Manually edit the Path @@ -155,9 +155,9 @@ Again, the Path lookup order is: ### Adding Python to your Path -Here only the common case of adding Python and the Python Scripts directory to the Windows Path is detailed. However, knowing -how to manually modify the Path is handy beyond just Python for whenever you need to change or debug which programs run -on the command line in Windows. (The less customizable but [safer method is +Here only the common case of adding Python and the Python Scripts directory to the Windows Path is detailed. However, +knowing how to manually modify the Path is handy beyond just Python for whenever you need to change or debug which +programs run on the command line in Windows. (The less customizable but [safer method is above](#safe-method-let-the-installer-add-python-to-path) if you missed it.) Follow these steps to add Python to the Path. **You will need administrator privileges on your computer.** @@ -209,9 +209,9 @@ Follow these steps to add Python to the Path. **You will need administrator priv (Don't worry if your variables or Path contents differ a bit from those shown.) -6. Now a third window opens and this is where the Path is actually edited. It shows the ordered list of the folders on the - Path and you can select the entries, edit them, reorder them, make new ones, delete them and so on. (Don't delete - any unless you know what you're doing!) +6. Now a third window opens and this is where the Path is actually edited. It shows the ordered list of the folders on + the Path and you can select the entries, edit them, reorder them, make new ones, delete them and so on. (Don't + delete any unless you know what you're doing!) We want to add the Python executable path we found in step 1 as a new entry, so click "New" and paste in the path. -- cgit v1.2.3 From d59465bd63adcf9ac1b63ffdc0e5468321a4977c Mon Sep 17 00:00:00 2001 From: discretegames Date: Sun, 13 Nov 2022 10:43:24 -0800 Subject: removed import workaround and mentioned 32-bit download in windows guides --- .../resources/guides/python-guides/windows/common-issues.md | 4 ++-- .../python-guides/windows/installing-and-using-python.md | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md index 65633609..b8153e86 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/common-issues.md @@ -62,8 +62,8 @@ with `py`. See [this guide](../installing-and-using-python/#the-py-launcher) for - [**Pillow**](https://pypi.org/project/Pillow/): You need to `pip install Pillow`, but the import is usually `from PIL import Image`. - Normal imports in Python can't have dashes (`-`) in them as it would be interpreted as subtraction. Though [there - are workarounds](https://stackoverflow.com/questions/7583652/python-module-with-a-dash-or-hyphen-in-its-name). + Normal imports in Python can't have hyphens (`-`) in them as it would be interpreted as subtraction. So if the + package name has a `-` in it the import will definitely be different. - #### Are you installing to the same environment you're running your code from? diff --git a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md index cbfc17a3..81fe4cbb 100644 --- a/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md +++ b/pydis_site/apps/content/resources/guides/python-guides/windows/installing-and-using-python.md @@ -34,11 +34,13 @@ Windows 11 or other modern versions of Python.) > version compatibility or for working on projects made in a certain version. Only uninstall things if you want to. 1. Go to [python.org/downloads](https://www.python.org/downloads) and click the big yellow "Download Python 3.x.x" - button near the top of the page. That should start the download of the installer for the latest version that best - suits your computer. + button near the top of the page. That should start the download of the installer (a file like + `python-3.11.0-amd64.exe`) for the latest version of Python. - If you want a different version or it doesn't work for some reason, you can download the - Windows installer you want from [python.org/downloads/windows](https://www.python.org/downloads/windows). + If you want a different version or it doesn't work for some reason, you can download the Windows installer you want + from [python.org/downloads/windows](https://www.python.org/downloads/windows). If you still have a [32-bit operating + system](#32-bit-vs-64-bit) you'll need to go here and look for the latest "Windows installer (32-bit)" because the + yellow button downloads the 64-bit installer by default. [![Step 1](/static/images/content/python-on-windows/recommended_install_1.png)](/static/images/content/python-on-windows/recommended_install_1.png) -- cgit v1.2.3