Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash查找python可执行文件的位置错误_Python_Git_Bash - Fatal编程技术网

bash查找python可执行文件的位置错误

bash查找python可执行文件的位置错误,python,git,bash,Python,Git,Bash,每当我尝试在Windows上使用Git Bash终端运行python命令时,它都会出现在错误的位置: $ python --version C:/Program Files/Git/usr/bin/python.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory 包含python可执行文件的文件夹已添加到PATH变量: $ $PATH b

每当我尝试在Windows上使用Git Bash终端运行python命令时,它都会出现在错误的位置:

$ python --version
C:/Program Files/Git/usr/bin/python.exe: error while loading shared libraries: 
?: cannot open shared object file: No such file or directory
包含python可执行文件的文件夹已添加到PATH变量:

$ $PATH
bash: /mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/f/bin:/c/_Programming/Python/Installation/Python36-32/Scripts:/c/_Programming/Python/Installation/Python36-32:/c/_Programming/Ruby/Installation/RailsInstaller/Git/cmd:/c/_Programming/Ruby/Installation/RailsInstaller/Ruby2.3.0/bin:/cmd:/usr/bin/vendor_perl:/usr/bin/core_perl: No such file or directory
我不明白为什么Git Bash终端在路径之外的位置查找python。 从Windows终端访问python效果很好:

C:\Windows\System32>python --version
Python 3.6.2

如何让Git Bash为python使用正确的位置?

我猜Git usr/bin目录:/usr/bin有一个python可执行文件,在/c/_编程/python/Installation/Python36-32/脚本之前先读取它(我假设您已经在那里安装了python exec)。尝试将路径更改为prefix/c/_Programming/Python/Installation/Python36-32/Scripts

git bash和Windows控制台是两个完全不同的命令行程序。Git bash是一个移植到Windows的基于Linux的终端(有自己的一组库),因此为了让Git bash知道程序在哪里,必须手动执行。我的意思是,您还必须在gitbash中设置PATH变量。解释如何做。简而言之,这就是您需要做的:

  • 以启动Windows程序的通常方式启动Git Bash程序。安装过程中创建了Git Bash的快捷方式
  • 在命令提示下,粘贴此命令export PATH=“$PATH:/c/Python27”。这将告诉Windows在哪里可以找到Python。(这假设您是在C:\Python27中安装的,正如我们在上面告诉您的那样)
  • 通过输入命令python--version,检查以确保该操作正常运行。它应该是Python2.7.8(或2.7.something),如下图所示
  • 假设工作正常,您将需要设置GitBash,以便它始终知道在哪里可以找到python。为此,请输入以下命令:echo'export PATH=“$PATH:/c/Python27”>.bashrc。这将把命令保存到一个名为.bashrc.的文件中。每次gitbash启动时都会执行bashrc,因此您不必再次手动告诉shell在哪里可以找到python
  • 通过键入exit、重新启动gitbash,然后再次键入python--version,检查以确保该操作正常

  • 这不起作用——正如我在问题中所说的,包含python的文件夹已经在git bash路径变量中,但git bash忽略了这一点,并在其他地方查找。这可能是问题所在——该目录中有一个python可执行文件(尽管我一开始没有注意到)。我认为你的解决方案会奏效,但我最终只是卸载并重新安装了Git for Windows,它修复了所有问题。