【问题标题】:Why do I get a ModuleNotFoundError for winreg on a Linux system?为什么我会在 Linux 系统上收到针对 winreg 的 ModuleNotFoundError?
【发布时间】:2019-01-17 14:01:51
【问题描述】:

'winreg' 模块未找到 python 3.6.7。我在 Python 3.4 中没有遇到这个问题。

'winreg' 中是否有任何第三方应用程序可以使用相同的代码,或者我该如何解决这个问题。

jaki@jaki-notebook:~$ python3 -V
Python 3.6.7
jaki@jaki-notebook:~$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from winreg import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'winreg'
>>> 

ModuleNotFoundError: 没有名为“winreg”的模块

【问题讨论】:

  • 你在windows上吗?你确定你使用的是 Python 3 吗?它在 Python 2 中被命名为_winreg。你能详细说明你是如何称呼它的吗?了解如何创建minimal reproducible example
  • 我使用的是Linux,python版本是“Python 3.6.7”
  • 如果您使用的是 Linux,则没有 Windows 注册表。所以没有winreg 模块,因为即使它在那里也无能为力。如果 winreg 导入来自第三方包,则它可能应该具有用于​​在非 Windows 系统上进行配置的替代机制。如果是您自己的代码,您只需要在非 Windows 系统上使用不同的配置机制,而不是 winreg
  • @Jaki:当你说“我在 Python 3.4 中没有遇到这个问题”时:有问题的 Python 3.4 发行版是否也安装在 Linux 系统上,或者那是 Windows 系统?
  • 为什么要在 Linux 上导入 winreg

标签: python python-3.6 winreg


【解决方案1】:

它不适用于 linux 因为这个包expose functions of the Windows registry API to Python

阅读python官网this文档

【讨论】:

    猜你喜欢
    • 2019-05-04
    • 2017-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多