在 macos 中使用 textmate 執(zhí)行腳本如下:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
print("hello, world!!!")
報(bào)出錯(cuò)誤:env: python3: No such file or directory
改為 env python 就可以順利執(zhí)行。
在 TextMate 的 Preferences -> variables 查看環(huán)境變量 PATH 的值為:
$PATH:/opt/local/bin:/usr/texbin:/usr/local/bin
在 MacOS 中漫雷,python3 的路徑為 /usr/local/bin/python3但骨,python 的路徑為 /usr/bin/python
系統(tǒng)中的 PATH 環(huán)境變量為:
$ echo $PATH
/Users/guli/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
是沒錯(cuò)的,包含了 python3 和 python 的路徑哟冬,那為什么在 textmate 中只能調(diào)用 python 而不能調(diào)用 python3 呢先改?
然后搜索到一篇 textmate 的博客:大意是 textmate 沒有繼承 MacOS 的環(huán)境變量設(shè)置召娜,因?yàn)樗鼪]有解析 shell 的啟動(dòng)腳本恢暖。所以如果執(zhí)行的命令在默認(rèn) PATH 路徑之外的話排监,需要在 textmate 的設(shè)置中添加命令的路徑。
好了杰捂,那奇怪的點(diǎn)在于舆床,textmate 路徑也是對(duì)的。為啥還是不行呢。
試了試挨队,有兩種方法是可以的:
1谷暮,在 python 腳本改寫第一行,直接寫上python3的路徑:
#!/usr/local/bin/python3
# -*- coding:utf-8 -*-
2盛垦,在 textmate 的 PATH 設(shè)置中湿弦,添加python3的命令路徑:
$PATH:/opt/local/bin:/usr/texbin:/usr/local/bin:/usr/local/bin/python3
好了,最奇怪的事來了腾夯,我后來把這兩種改動(dòng)都還原了省撑,但是也可以執(zhí)行成功了。
但暫時(shí)就這樣先俯在,不再研究下去了,先用著娃惯,已經(jīng)花了1個(gè)小時(shí)折騰這個(gè)事情了跷乐。
下面是參考的那篇textmate博客文檔:
Defining a $PATH
http://blog.macromates.com/2014/defining-a-path/
Upcoming changes to OS X have caused us to make some changes in TextMate that have been causing some users to see a env: ruby18: No such file or directory error when running bundle items. This is caused by improper setup of the PATH variable, but lets go over what this variable does and how to correct the issue.
OS X comes with many command line tools that TextMate takes advantage of such as ruby, python, git, etc. To find these programs there is the environment variable PATH which is a list of paths that is used to find the required tools.
Note that while you may already have set the PATH variable for your shell (e.g. bash) it is not inherited in TextMate, as TextMate does not parse your shell setup scripts. For commands that require tools outside the default path list, like the LaTeX typeset command, we normally provide a list of common locations that TextMate should also search, so you normally should not need to change the PATH in TextMate.
To add to the PATH variable inside TextMate open Preferences and go to the Variables section and add a new item with the name of PATH. It is important that the value set augment the existing value instead of replacing it. To do this you should prefix the value with $PATH:. Example values for common uses:
MacPorts: $PATH:/opt/local/bin
Homebrew: $PATH:/usr/local/bin
This post relates to TextMate 2.0 only.