繁体   English   中英

MacOS 终端命令“python3 file.py”进入目录而不是从 PATH 执行脚本文件

[英]MacOS terminal command 'python3 file.py' goes into directory instead of executing script file from PATH

我在 .bash_profile 中添加了一个自定义 PATH 并且我想在没有 cd-ing 到目录的情况下运行脚本文件。

但是,当我尝试在终端中使用python3 gmail.pypython gmail.py时,它给了我以下错误: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3: can't open file 'gmail.py': [Errno 2] No such file or directory

我在 Python 2.7 的顶部安装了 Anaconda 和 Python 3.8,MacOS 带有 vanilla。 我怀疑当我输入 python3 时,它会在 Python 3 文件夹目录下搜索,而不是将其识别为运行文件命令。

我的 .bash_profile 看起来像这样:

# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/stevenwang/opt/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/Users/stevenwang/opt/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/stevenwang/opt/anaconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/Users/stevenwang/opt/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

# Setting PATH for Python 3.8
# The original version is saved in .bash_profile.pysave
export PATH=${PATH}:/desktop/script/
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
export PATH

我是否在设置 PATH 时出错,或者终端命令是否存在冲突?

非常感谢!

这不是PATH所做的; 此外,没有 Python 搜索的环境变量。 通常,您会放置一个包装shell脚本,该脚本知道脚本在PATH上的位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM