您好,我正在尝试直接从终端运行 python 脚本。为此,我已将包含代码的目录添加到我的环境 PATH 变量中。但是,当我指定完整路径时我可以运行,但当我只调用脚本时则不能运行。
(base) DS:~ $ /home/user_abc/my_codes/status.py
Everything is ok!
(base) DS:~ $ echo $PATH
/home/user_abc/anaconda3/bin:/home/user_abc/mycodes:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/bin
(base) DS:~ $ status.py
-bash: status.py: command not found
(base) DS:~ $ /status.py
-bash: /status.py: No such file or directory
(base) DS:~ $ ./status.py
-bash: ./status.py: No such file or directory
(base) DS:~ $
我的舍邦看起来像这样。
#!/home/user_abc/anaconda3/bin/python3
(base) DS:~ $ python3 status.py
python3: can't open file status.py': [Errno 2] No such file or directory
(base) DS:~ $ python status.py
python: can't open file 'status.py': [Errno 2] No such file or directory
(base) DS:~ $
虽然我不需要 python,只是想像任何其他命令一样调用脚本。
您的 PATH 不包括脚本的路径。
你提到过/home/user_abc/mycodes
在你的路径中,但 python 脚本的位置在/home/user_abc/my_codes/
运行此命令来修复问题。
$ export PATH=$PATH:/home/user_abc/my_codes
$ status.py
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)