bash 终端中无法正常使用python
Bash终端中python环境异常
背景
正常安装python之后,在cmd终端中能正常使用python,但是在bash终端中无法使用python执行py脚本,同时通过which python查询输出py目录
where python
D:\a-software\Python314\python.exe
C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps\python.exe
which python
/c/Users/Administrator/AppData/Local/Microsoft/WindowsApps/python
这说明bash中没有正确的python环境,即使python在安装时设置了系统环境变量。
解决方案
1、如果没有python环境,先执行下面的命令,否则直接跳到第2步,从第二步开始
# 添加系统环境变量
export PATH="D:/a-software/Python314:$PATH"
2、永久修改
nano ~/.bashrc
输入export PATH="D:/a-software/Python314:$PATH",保存并退出(ctrl+o ---> ctrl+x)
3、重启配置,使得配置生效
source ~/.bashrc
4、重启bash终端,vscode中得关闭vscode后重启,此时在bash终端中查看which python这是后应该变成了/d/a-software/Python314/python,这就正常了
本文来自博客园,作者:南宫影,转载请注明原文链接:https://www.cnblogs.com/nangongying/p/19184998

浙公网安备 33010602011771号