700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python no such file or directory_Python3 no such file or directory

python no such file or directory_Python3 no such file or directory

时间:2023-07-17 20:10:03

相关推荐

python no such file or directory_Python3 no such file or directory

问题

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.

来源:/questions/27008257/python3-no-such-file-or-directory

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。