问题描述:
由于某些安装失误或者其他原因导致sys.path 中添加了不想要的路径
原因分析:
参考site得知:
A path configuration file is a file whose name has the form name.pth and exists in one of the four directories mentioned above; its contents are additional items (one per line) to be added to sys.path. Non-existing items are never added to sys.path, and no check is made that the item refers to a directory rather than a file. No item is added to sys.path more than once. Blank lines and lines beginning with # are skipped. Lines starting with import (followed by space or tab) are executed.
路径配置文件是一个文件,其名称具有表单名称.PTH,并且存在于上述四个目录之一中; 其内容是将添加到sys.path的其他项目(每行一个)。 非现有项目永远不会添加到sys.path,并且没有检查该项目是指目录而不是文件。 没有项目被添加到sys.path不止一次。 跳过了与#开头的空白行和行。 执行以导入(后跟空间或标签)开始的行。
解决方案:
在python导入目录(比如:/home/**/anaconda3/envs/main/lib)下搜索.pth,一般包含setuptools.pth, easy-install.pth等,逐个打开找到并删除目标路径.
当sys.path中出现不期望的路径时,可能由安装错误引起。解决方法包括查找和编辑.pth文件,这些文件通常位于Python导入目录下,如/home/**/anaconda3/envs/main/lib。打开.pth文件,删除不需要的路径,以保持sys.path的正确性。
2138

被折叠的 条评论
为什么被折叠?



