我想编写一个脚本来清理机器上所有现有的Python版本,并编写一个单独的脚本来在标准位置重新安装2.7和3.5版本的Python。我目前正尝试使用PowerShell 5.1.14393.187中的来完成这项工作。
对于清理脚本,我从PowerShell的包命令开始:
Get-Package "*python*" | Uninstall-Package
当从管理控制台运行时,似乎工作得很好,但是在进一步的调查中,仍然有一些包.
PS C:\WINDOWS\system32> Get-Package "*python*"
Name Version Source ProviderName
---- ------- ------ ------------
Python 3.5.1 (64-bit) 3.5.1150.0 Programs
Python 3.5.1 pip Bootstrap ... 3.5.1150.0 msi
Python 3.5.1 Tcl/Tk Support... 3.5.1150.0 msi
Python 2.7.11 2.7.11150 msi
Python 3.5.2 pip Bootstrap ... 3.5.2150.0 msi
Python 3.5.2 (32-bit) 3.5.2150.0 Programs
为什么这些包在卸载包之后仍然存在?有什么最好的方法吗?是否有最佳实践方法来编写Python的重新安装脚本,这样就不会再发生这种情况了?
更新
通过使用控制面板GUI进行第一次修复,然后卸载Python 3安装,我已经成功地清理了其中的大部分。我很惊讶没有Repair-Package
命令可以与Get-Package
一起使用。
一旦修复了Python3的其他部分,就有一个名为"Python“的MSI包,Get-Package
仍然报告了Python2.7MSI包,但是GUI中没有任何东西。此时,"Python“上的Uninstall-Package
成功,并警告说需要重新启动。msi没有这样的运气:Python2.7.11/2.7.11150。
其他信息:
我认为巧克力v0.10.1可能是造成当前情况的原因。至少有一些机器已经安装了python,使用的是来自公共存储库的巧克力。在上面的同一台机器上,我也尝试过这样做:
PS C:\WINDOWS\system32> choco uninstall python
Chocolatey v0.10.1
Uninstalling the following packages:
python
python is not installed. Cannot uninstall a non-existent package.
Chocolatey uninstalled 0/1 packages. 1 packages failed.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Failures
- python - python is not installed. Cannot uninstall a non-existent package.
Did you know the proceeds of Pro (and some proceeds from other
licensed editions) go into bettering the community infrastructure?
Your support ensures an active community, it makes you look smarter,
plus it nets you some awesome features!
https://chocolatey.org/compare
PS C:\WINDOWS\system32> choco uninstall python3
Chocolatey v0.10.1
Uninstalling the following packages:
python3
python3 v3.5.1
Skipping auto uninstaller - No registry snapshot.
python3 has been successfully uninstalled.
Chocolatey uninstalled 1/1 packages. 0 packages failed.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
PS C:\WINDOWS\system32> choco uninstall python2
Chocolatey v0.10.1
Uninstalling the following packages:
python2
python2 v2.7.11
Running auto uninstaller...
Skipping auto uninstaller - The application appears to have been uninstalled already by other means.
python2 has been successfully uninstalled.
Chocolatey uninstalled 1/1 packages. 0 packages failed.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
PS C:\WINDOWS\system32> get-package "*python*"
Name Version Source ProviderName
---- ------- ------ ------------
Python 3.5.1 (64-bit) 3.5.1150.0 Programs
Python 3.5.1 pip Bootstrap ... 3.5.1150.0 msi
Python 3.5.1 Tcl/Tk Support... 3.5.1150.0 msi
Python 2.7.11 2.7.11150 msi
Python 3.5.2 pip Bootstrap ... 3.5.2150.0 msi
发布于 2016-09-27 17:06:42
为了回答这个问题,我要强调几点,供你们考虑。
为什么卸载包后这些包仍然存在?
这真的取决于你过去安装软件包的方式,以及巧克力是否能够捕捉到自动卸载程序的快照。
许多包不需要卸载脚本。有些人有。当他们是MSI并且升级到巧克力之外(就像Chrome自动做的那样),你要么需要包装同步器或者卸载脚本来卸载这个软件。
,有什么最佳实践方法吗?
如果这是用于组织,而且您对破坏的容忍度很低,我们建议您构建自己的内部包。然后,您可以完全控制过程,并有一个可重复的,可靠的过程。这就是数百个使用巧克力的组织目前如何加强安装过程的方式。他们通常已经有一些内部文件共享上的软件安装程序,并围绕着它们构建包来利用更好的自动化过程(相对于他们可能使用的旧批处理文件,或者更糟的是手动安装)。
如果您对为什么要构建自己的存储库感到好奇,请参阅https://chocolatey.org/docs/community-packages-disclaimer (它试图用公共存储库突出显示问题,并且它受发行权的约束,内部存储库不受此限制)。
是否有最佳实践方法来编写python的重新安装脚本,这样就不会再发生这种情况了吗?
使用配置管理工具,如木偶,厨师,Ansible,或DSC巧克力供应商。https://chocolatey.org/docs/features-infrastructure-automation
这就是您如何在所有机器上创建自动化并利用包管理的方式。
https://stackoverflow.com/questions/39710224
复制相似问题