天坑的:Fatal Python error: init_sys_streams: can‘t initialize sys standard streams解决方案

【问题描述】
今天用pycharm新建工程突然提示:编译环境有问题,简单写了两行代码测试一直有问题, 报错如下:
Fatal Python error: init_sys_streams: can’t initialize sys standard streams
在这里插入图片描述
【原因分析】
找了很多解决方案,结合错误提示,还是问题发生在虚拟环境下lib目录中的io.py身上,网上有好多老铁说改文件名字,然而证明并没有什么用,认真看下文件信息和内容发现并无区别,最后突然发现io.py的生成日期不对,恒新鲜,不是新建环境的那个日期,问题就出在这里,
【解决方案】因为都是标准文档,所以我们只需要把虚拟环境中,有io.py的生成日期为环境生成日期的io.py拷贝并替换掉日期异常的io.py文件问题瞬间解决。坑了我小半天的时间,真心无语。

io.py一般在虚拟环境的Lib目录下,具体代码如下:

"""The io module provides the Python interfaces to stream handling. The
builtin open function is defined in this module.

At the top of the I/O hierarchy is the abstract base class IOBase. It
defines the basic interface to a stream. Note, however, that there is no
separation between reading and writing to streams; implementations are
allowed to raise an OSError if they do not support a given operation.

Extending IOBase is RawIOBase which deals simply with the reading and
writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide
an interface to OS files.

BufferedIOBase deals with buffering on a raw byte stream (RawIOBase). Its
subclasses, BufferedWriter, BufferedReader, and BufferedRWPair buffer
streams that are readable, writable, and both respectively.
BufferedRandom provides a buffered interface to random access
streams. BytesIO is a simple stream of in-memory bytes.

Another IOBase subclass, TextIOBase, deals with the encoding and decoding
of streams into text. TextIOWrapper, which extends it, is a buffered text
interface to a buffered raw stream (`BufferedIOBase`). Finally, StringIO
is an in-memory stream for text.

Argument names are not part of the specification, and only the arguments
of open() are intended to be used as keyword arguments.

data:

DEFAULT_BUFFER_SIZE

   An int containing the default buffer size used by the module's buffered
   I/O classes. open() uses the file's blksize (as obtained by os.stat) if
   possible.
"""
# New I/O library conforming to PEP 3116.

__author__ = ("Guido van Rossum <guido@python.org>, "
              "Mike Verdone <mike.verdone@gmail.com>, "
              "Mark Russell <mark.russell@zen.co.uk>, "
              "Antoine Pitrou <solipsis@pitrou.net>, "
              "Amaury Forgeot d'Arc <amauryfa@gmail.com>, "
              "Benjamin Peterson <benjamin@python.org>")

__all__ = ["BlockingIOError", "open", "IOBase", "RawIOBase", "FileIO",
           "BytesIO", "StringIO", "BufferedIOBase",
           "BufferedReader", "BufferedWriter", "BufferedRWPair",
           "BufferedRandom", "TextIOBase", "TextIOWrapper",
           "UnsupportedOperation", "SEEK_SET", "SEEK_CUR", "SEEK_END"]


import _io
import abc

from _io import (DEFAULT_BUFFER_SIZE, BlockingIOError, UnsupportedOperation,
                 open, FileIO, BytesIO, StringIO, BufferedReader,
                 BufferedWriter, BufferedRWPair, BufferedRandom,
                 IncrementalNewlineDecoder, TextIOWrapper)

OpenWrapper = _io.open # for compatibility with _pyio

# Pretend this exception was created here.
UnsupportedOperation.__module__ = "io"

# for seek()
SEEK_SET = 0
SEEK_CUR = 1
SEEK_END = 2

# Declaring ABCs in C is tricky so we do it here.
# Method descriptions and default implementations are inherited from the C
# version however.
class IOBase(_io._IOBase, metaclass=abc.ABCMeta):
    __doc__ = _io._IOBase.__doc__

class RawIOBase(_io._RawIOBase, IOBase):
    __doc__ = _io._RawIOBase.__doc__

class BufferedIOBase(_io._BufferedIOBase, IOBase):
    __doc__ = _io._BufferedIOBase.__doc__

class TextIOBase(_io._TextIOBase, IOBase):
    __doc__ = _io._TextIOBase.__doc__

RawIOBase.register(FileIO)

for klass in (BytesIO, BufferedReader, BufferedWriter, BufferedRandom,
              BufferedRWPair):
    BufferedIOBase.register(klass)

for klass in (StringIO, TextIOWrapper):
    TextIOBase.register(klass)
del klass

try:
    from _io import _WindowsConsoleIO
except ImportError:
    pass
else:
    RawIOBase.register(_WindowsConsoleIO)

  • 7
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 16
    评论
### 回答1: 这个错误提示意味着Python解释器无法初始化标准输入/输出流。通常这是由于环境配置错误或者Python解释器本身出现问题引起的。 解决这个问题的方法包括: 1. 检查系统环境变量和Python配置是否正确设置。 2. 确认你正在使用的Python版本是正确的,并且没有安装问题。 3. 尝试重新安装Python并更新系统环境变量。 如果这些方法无法解决问题,那么可能需要更深入的排查和诊断,建议寻求专业人士的帮助。 ### 回答2: 这个错误是Python解释器在启动过程中遇到的一个致命错误。 它通常表示Python解释器无法初始化标准流,这包括stdin,stdout和stderr。 该错误可能由多种因素引起,例如损坏的安装或配置文件,无法访问文件,权限问题或某些计算机上的其他软件冲突。 要解决此错误,可以尝试以下一些方法: 1. 检查Python安装是否正确。在重新安装Python之前可以尝试修复安装。 2. 检查文件或目录权限,确保Python可以访问标准流。 3. 确保没有其他软件与Python冲突。可能需要关闭或卸载其他软件。 4. 检查Python配置文件是否损坏或失效。 5. 尝试升级或降级Python版本。 6. 尝试在操作系统级别重置stdin,stdout和stderr。这可能需要高级技能,因此应小心操作。 如果以上方法无法解决问题,则需要更深入地调查和诊断这个问题。可以查看Python的日志文件以了解更多信息,或者检查操作系统日志以寻找有关发生错误的更多详细信息。 ### 回答3: 这个错误是由于系统无法初始化Python标准流而引起的致命错误。Python标准流是指标准输入、输出和错误流。当Python解释器无法初始化这些流时,它就无法继续运行,导致程序崩溃。 通常情况下,这个错误可能是由于以下原因之一引起的: 1. 系统环境变量错误或损坏:在某些情况下,系统环境变量可能会发生错误或受到损坏,这可能导致Python无法正确初始化标准流。 2. Python配置文件错误:Python配置文件可能包含有关Python环境和设置的信息。如果配置文件存在错误或损坏,Python解释器将无法正确初始化标准流,从而导致程序崩溃。 3. 操作系统错误:在某些情况下,操作系统可能会发生错误,例如文件系统错误或其他硬件故障,这可能会导致Python解释器无法初始化标准流。 为了解决这个错误,可以尝试以下步骤: 1. 确认系统环境变量已经正确配置并且没有损坏。可以通过在终端中运行“echo $PATH”来检查系统环境变量。 2. 检查Python配置文件是否存在错误或损坏。可以通过卸载并重新安装Python解决此问题。 3. 尝试修复操作系统错误,例如通过运行磁盘检查和修复工具来修复文件系统错误。 总的来说,fatal python error: init_sys_streams: can't initialize sys standard streams错误是一个比较严重的问题,需要细心检查处理,从而避免其造成的损失和影响。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

时间之里

好东西就应该拿出来大家共享

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值