python no such file or directory_Python3 no such file or directory

在尝试从shell运行Python3脚本时遇到'No such file or directory'错误。解决方案包括:确保Python3解释器全局可用,通过编辑.bash_profile或.bashrc文件将Python3路径添加到PATH环境变量;或者在脚本顶部添加shebang(#!/usr/bin/env python3.4.0),并给予脚本执行权限。
摘要由CSDN通过智能技术生成

问题

I am trying to make python3 executable scripts and run them from shell.I have python 3.4.0 installed on my system.

So, I added '/home/spandan/python_codes' directory to PYTHONPATH, as I am planning to keep my scripts and modules here.

However, while trying to execute these, the above error is thrown by the system, and the scripts wont execute unless I go into the python_codes directory and then execute them.

Executing python program : Here I found out that PYTHONPATH is irrelevant while making scripts, and also how to set the python shebang. So I set mine as #!/usr/bin/env python3.4.0

Is it Correct? Please help.

Thanks, Spandan.

回答1:

You don't have to put your python codes in a global path. Just make your python 3.4 interpreter interpreter available globally. For that, edit .bash_profile or .bashrc file in your home directory and add the following line:

export PATH=${PATH}:/usr/bin/python3

That will make python3 executable irrespective of your current working directory.

In order to execute code from your codes directory, you just have to write:

$ python3 ./your_code.py

Another way is to add the shebang at the top of your code as

#/usr/bin/python3

and change the permission to executable by the current user (by default it will not have execute permission).

$ chmod 744 your_code.py

and then executing the script directly as

$ your_code.py

I hope I could address your problem.

来源:https://stackoverflow.com/questions/27008257/python3-no-such-file-or-directory

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值