简体   繁体   English

在 Windows 上彻底重新安装 Python 的最佳方法是什么?

[英]What is the best way to make a clean reinstall of Python on Windows?

I tried to update Python 3.8.5.我尝试更新 Python 3.8.5。 to 3.8.10 on a Windows 7 machine, but some part of Python's and/or pip 's messy installer/path/package management system bricked everything.到 Windows 7 机器上的 3.8.10,但 Python 和/或pip凌乱安装程序/路径/包管理系统的某些部分使一切都变砖了。 Nobody I asked knows a canonical solution to this + pretty much everybody is suggesting a complete reinstallation.我问过的人都不知道这个问题的规范解决方案+几乎每个人都建议完全重新安装。

Which is why I've now completely removed Python and have to reinstall Python, pip , and all my packages one by one.这就是为什么我现在完全删除了 Python 并且必须一一重新安装 Python、 pip和我所有的包的原因。 I've already uninstalled/removed Python and pip and downloaded the official Python 3.8.10 64-bit Windows installer as well as get-pip.py .我已经卸载/删除了 Python 和pip并下载了官方 Python 3.8.10 64 位 Windows 安装程序以及get-pip.py

But despite spending days and days of reading, I can't see through Python's complicated mess of "user-specific vs. local vs. system-wide" installation schemes, varying package installations paths, the seemingly arbitrary variations introduced by using python vs. python -m , pip install vs. pip install --user etc. during package installations, and the regular whining about some PATH environment variables not being set properly etc. pp. - if you've ever used Python professionally, you'll have an idea of what I'm describing here.但是,尽管花费了数天的阅读时间,我还是看不透 Python 复杂的“用户特定 vs. 本地 vs. 系统范围”安装方案、不同的包安装路径、使用python和使用 Python 引入的看似任意的变化。 python -mpip installpip install --user等在软件包安装过程中,以及关于一些 PATH 环境变量设置不正确等的常规抱怨。 pp. - 如果你曾经专业使用过 Python,你会我在这里描述的想法。

Anyway - what I want to do now is make one clean installation where I stick to one set of rules for everything.无论如何 - 我现在想做的是进行一次干净的安装,我坚持一套规则来处理所有事情。 All packages installed to one single superdirectory (vs. getting scattered all over the system) and all PATH variables set accordingly to the most universal and complete configuration possible (I don't want to see any complaints from Python ever again in this regard).所有软件包都安装到一个单一的超级目录(而不是分散在整个系统中),并且所有 PATH 变量都根据可能的最通用和最完整的配置进行设置(我不想再看到 Python 在这方面的任何抱怨)。 Note that I'm the administrator of the machine, but working from a normal user account with Windows UAC enabled and want an installation for all users - the most general solution possible, no limiting scenarios that may cause the very problems I'm trying to avoid.请注意,我是机器的管理员,但使用启用了Windows UAC的普通用户帐户工作,并希望为所有用户安装 - 可能是最通用的解决方案,没有可能导致我试图解决的问题的限制场景避免。

Also, I do not want to use virtual environments for now, but this is different topic I'm already working on independently.另外,我现在不想使用虚拟环境,但这是我已经独立研究的不同主题。 So no suggestions regarding venv .所以没有关于venv的建议。

Question: How to procede with the installation?问题:如何进行安装?

Possible sub-issues that need to be addressed:可能需要解决的子问题:

  1. Correct privileges for the Windows installer, eg the confusing "for all users (requires elevation)" and subsequent (second!) "Install for all users" options. Windows 安装程序的正确权限,例如令人困惑的“所有用户(需要提升)”和后续(第二个!) “为所有用户安装”选项。 The latter changes the installation path from C:\Users\<Username>\AppData\Local\Programs\Python\Python38 to C:\Program Files\Python38 and Windows UAC may prevent access of Python and/or pip to C:\Program Files\ without proper exception handling (eg user prompt) in place:后者将安装路径从C:\Users\<Username>\AppData\Local\Programs\Python\Python38C:\Program Files\Python38并且 Windows UAC 可能会阻止访问 Python 和/或pipC:\Program Files\没有适当的异常处理(例如用户提示):

截屏

  1. Usage of get-pip.py vs. some other methods to install pip , which also concerns the usage of python vs. python -m vs. pip install vs. pip install --user etc. in this context and subsequent installation of user packages.使用get-pip.py与其他一些安装pip的方法,这也涉及在此上下文中使用pythonpython -mpip installpip install --user等以及随后安装用户包.

  2. Prevention of scattering/fragmentation of the Python development framework over the system/different folders/different users, causing eg annoying PATH or dependency issues/conflicts.防止 Python 开发框架在系统/不同文件夹/不同用户上的分散/碎片化,导致例如烦人的 PATH 或依赖问题/冲突。

  3. Defining the correct set of Windows path variables under these requirements and addressing concerns/doubts about Python's and pip 's ability of reliably handling this issue on their own.根据这些要求定义正确的 Windows 路径变量集,并解决对 Python 和pip自行可靠处理此问题的能力的担忧/怀疑。

Note: I'm the owner/only user on this machine and therefore have administrator rights.注意:我是这台机器的所有者/唯一用户,因此拥有管理员权限。 Managing installations/environments for multiple users is not the subject here and of no interest for me.为多个用户管理安装/环境不是这里的主题,我也不感兴趣。

Anyway - what I want to do now is make one clean installation where I stick to one set of rules for everything.无论如何 - 我现在想做的是进行一次干净的安装,我坚持一套规则来处理所有事情。 All packages installed to one single superdirectory (vs. getting scattered all over the system) and all PATH variables set accordingly to the most universal and complete configuration possible (I don't want to see any complaints from Python ever again in this regard).所有软件包都安装到一个单一的超级目录(而不是分散在整个系统中),并且所有 PATH 变量都根据可能的最通用和最完整的配置进行设置(我不想再看到 Python 在这方面的任何抱怨)。

This is contradictory.这是矛盾的。 A single installation with a common set of rules, every possible installed package, comprehensive PATH etc. is inherently not "clean" .具有一组通用规则、每个可能安装的包、全面的 PATH 等的单个安装本质上不是“干净的” The point of maintaining separate installations is so that one user's changes do not unexpectedly impact on the operation of another user's code .维护单独安装的目的是使一个用户的更改不会意外影响另一个用户代码的操作 It is not possible to do this with a single installation.单次安装无法做到这一点。 If you upgrade a library, for example, it affects every user who wrote code that uses that library, who must now check for incompatibilities.例如,如果您升级一个库,它会影响每个编写使用该库的代码的用户,他们现在必须检查不兼容性。

Correct privileges for the Windows installer, eg the confusing "for all users (requires elevation)" and subsequent (second!) "Install for all users" options. Windows 安装程序的正确权限,例如令人困惑的“所有用户(需要提升)”和后续(第二个!)“为所有用户安装”选项。

The first one means "Install the launcher for all users", which is why that checkbox is on the same line as "py launcher".第一个表示“为所有用户安装启动器”,这就是该复选框与“py 启动器”位于同一行的原因。 (If you are not familiar with the Python launcher for Windows , please read the documentation .) it says "(requires elevation)" because the installer requires elevation in order to install this feature for all users. (如果您不熟悉Windows 的 Python 启动器,请阅读文档。)它显示“(需要提升)”,因为安装程序需要提升才能为所有用户安装此功能。 You do not need to do this if you have installed it from a previous version of Python.如果您是从以前版本的 Python 安装的,则无需执行此操作。

and subsequent (second!) "Install for all users" options.以及随后的(第二个!)“为所有用户安装”选项。

This is the option to install this version of Python for all users.这是为所有用户安装此版本 Python的选项。 The install directory changes according to the "for all users" setting, in the expected way.安装目录根据“所有用户”设置以预期方式更改。

Windows UAC may prevent access of Python and/or pip to C:\Program Files\ without proper exception handling (eg user prompt) in place如果没有适当的异常处理(例如用户提示),Windows UAC 可能会阻止访问 Python 和/或 pip 到 C:\Program Files\

It will prevent write access without elevation, yes.它会阻止没有提升的写访问,是的。 This is by design, and it is why the option exists for per-user installations.这是设计使然,这就是为什么存在按用户安装选项的原因。

pip requires write access, because its purpose is to install libraries. pip需要写权限,因为它的目的是安装库。 I do not know whether it can request elevation from the command prompt;我不知道它是否可以从命令提示符请求提升; probably not.可能不是。 You can work around this by using the command in an elevated command window.您可以通过在提升的命令窗口中使用该命令来解决此问题。 With UAC enabled, you will not be able to install libraries into a Python for-all-users installation (ie, in Program Files): it is the explicit purpose of UAC to prevent that sort of thing.启用 UAC 后,您将无法将库安装到适用于所有用户的 Python 安装中(即在程序文件中): UAC 的明确目的是防止这种事情发生。

Python normally does not require write access to these directories. Python通常不需要对这些目录进行写访问。 The standard library does not need write access once the library is installed.安装库后,标准库不需要写访问权。 There might be a problem if you uncheck "Precompile standard libraries";如果取消选中“预编译标准库”,可能会出现问题; I have not tested this and have stopped using Windows.我没有对此进行测试并已停止使用 Windows。 Third-party libraries normally will not require write access for their own installation directories, either.第三方库通常也不需要对自己的安装目录进行写访问。 If you encounter a problem, consult the documentation for that library.如果遇到问题,请查阅该库的文档。

Usage of get-pip.py vs. some other methods to install pip, which also concerns the usage of python vs. python -m vs. pip install vs. pip install --user etc. in this context and subsequent installation of user packages. get-pip.py 的使用与其他一些安装 pip 的方法,这也涉及在此上下文中使用 python vs. python -m vs. pip install vs. pip install --user 等以及后续安装用户包.

get-pip etc. are deprecated. get-pip等已被弃用。 They are tools intended to account for the fact that Python didn't always come bundled with pip .它们是旨在说明 Python 并不总是与pip捆绑在一起的事实的工具。 It does now.现在可以了。 pip works the same way regardless of whether it was bundled with Python or installed to an older Python version separately.无论它是与 Python 捆绑在一起还是单独安装到较旧的 Python 版本, pip的工作方式都是相同的。 There is not a clear question here;这里没有一个明确的问题; there are several specific things that need to be researched and understood about how to use pip.关于如何使用 pip,有几件具体的事情需要研究和理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Windows上安装python的最佳方法是什么? - What is the best way to install python on Windows 在 python 中进行猜测循环的最佳方法是什么? - What is the best way to make a guessing loop in python? 在 Python pandas DataFrame 中交换值以清理数据的最佳方法是什么 - What is the best way to swap values in Python pandas DataFrame to clean up the data 在 python 中获取 Windows PATH 的干净方法 - Clean way to get Windows PATHs in python 使用Python映射Windows驱动器的最佳方法是什么? - What is the best way to map windows drives using Python? 在python中用数据制作数组的最佳方法是什么? - What is the best way make an array out of my data in python? 在 python 中制作适应性强的 tkinter 按钮列表的最佳方法是什么? - What’s the best way to make adaptable tkinter button lists in python? 制作Python字典的浅表副本的最佳方法是什么? - What is the best way to make a shallow copy of a Python dictionary? 在 Python 中制作 integer 数字的单链表的最佳方法是什么? - What is the best way to make a singly linked list of integer digits in Python? 在线提供Python中的Assembly编译器的最佳方法是什么? - What's the best way to make an Assembly compiler in Python available online?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM