如何从sys.path中永久删除某个路径

问题描述:

由于某些安装失误或者其他原因导致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等,逐个打开找到并删除目标路径.

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值