目录
1.python启动时出现Failed calling sys.__interactivehook__的解决方法
问题描述:
在命令行cmd输入python
时,报下面这些信息
Failed calling sys.__interactivehook__
Traceback (most recent call last):
File "D:\Anaconda\lib\site.py", line 439, in register_readline
readline.read_history_file(history)
File "D:\Anaconda\lib\site-packages\pyreadline\rlmain.py", line 165, in read_history_file
self.mode._history.read_history_file(filename)
File "D:\Anaconda\lib\site-packages\pyreadline\lineeditor\history.py", line 82, in read_history_file
for line in open(filename, 'r'):
UnicodeDecodeError: 'gbk' codec can't decode byte 0x89 in position 224: illegal multibyte sequence
解决方法:
主要是根据命令行cmd的反馈信息一步步解决这个问题
1.找到history.py的文件位置
根据反馈信息可以找到处于D:\Anaconda\lib\site-packages\pyreadline\lineeditor\history.py
2.打开history.py并在82行加入“, encoding='utf-8‘ ”
即
for line in open(filename, 'r'):
改为
for line in open(filename, 'r', encoding='utf-8'):
3.打开命令行cmd,输入python
,不报信息了,问题解决~
2.修改pip默认缓存位置
问题描述:
清理C盘时发现pip文件夹占4G多,决定更改一下缓存位置。这个文件夹下放的是pip安装库时的缓存,不管安装成功与否,都会增加缓存。
解决方法:
pip默认缓存的位置是C:\Users\username\AppData\Local\pip\cache
我想要改变此路径为E:\cache\pipCache
具体操作方法:
在命令行中输入如下命令:pip config set global.cache-dir “E:\cache\pipCache”
得到反馈:Writing to C:\Users\username\AppData\Roaming\pip\pip.ini
恭喜你,修改成功~
3.Powershell / windows终端 无法加载文件 因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170
问题描述:
在 powershell 或者 windows 终端中运行脚本文件时,提示
无法加载文件 XXX,因为在此系统上禁止运行脚本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
原因分析:
PowerShell 或者 windows 终端启动时,为了确保安全,文件的执行策略默认设置为 Restricted 。
Restricted 执行策略不允许任何脚本运行
AllSigned 和 RemoteSigned 执行策略可防止 Windows PowerShell 运行没有数字签名的脚本
解决方法:
降低安全性等级,将执行策略改为 RemoteSigned 即可执行脚本
以管理员身份打开 PowerShell 或者 windows 终端,执行命令set-executionpolicy remotesigned
并确认(再输入个Y
)
然后再次运行该文件即可通过,
恢复默认设置
通过修改将降低系统的安全性,可能带来被病毒或恶意软件攻击的风险。
因此在执行完文件后,可以将设置改回默认,执行以下命令即可 set-executionpolicy Restricted
,这里同样需要进行确认(再输入个Y
)。
其他
如果需要了解计算机上的现用执行策略,可以打开PowerShell 然后输入 get-executionpolicy
有关文件的执行策略可参考:https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2
关于 Set-ExecutionPolicy 命令可参考:https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7.2