【问题标题】:How can I modify my .bash_profile file so I can run my python scripts w/o typing the path to the file? [closed]如何修改我的 .bash_profile 文件,以便在不输入文件路径的情况下运行我的 python 脚本? [关闭]
【发布时间】:2013-01-03 14:24:03
【问题描述】:

我是 OSX 新手,熟悉此环境中的文件结构。我的 .bash_profile 文件如下所示:

# Setting PATH for EPD_free-7.3-2
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
export PATH

我的脚本在几个目录中,例如:

/Users/LMS/Documents/pydata-book
/Users/LMS/Documents/python_scripts

我想做的是打开我的终端,输入脚本的名称(例如 myscript.py),然后执行,就像通过指定 *.py 文件与 Python 的关联一样,在windows 环境。

有人可以帮我用 mac 完成这个吗?

谢谢

【问题讨论】:

标签: python osx-lion epd-python


【解决方案1】:

尝试将其放入您的 .bash_profile 中:

# Setting PATH for EPD_free-7.3-2
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:/Users/LMS/Documents/pydata-book:/Users/LMS/Documents/python_scripts:${PATH}"

export PATH

基本上,你把包含你想要的可执行文件的目录,用':'分隔

【讨论】:

  • 谢谢。我按照您的指示做了,当我尝试通过键入 myscript.py 从终端运行我的脚本时,我得到了这个 -bash: /Users/LMS/Documents/pydata-book/myscript.py: Permission denied
  • 我认为您需要使脚本可执行,转到包含脚本的目录并执行chmod +x *.py
猜你喜欢
  • 1970-01-01
  • 2011-06-26
  • 1970-01-01
  • 1970-01-01
  • 2012-11-08
  • 2019-06-25
  • 1970-01-01
  • 2014-02-28
相关资源
最近更新 更多