问题

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

python no such file or directory_Python3 no such file or directory相关推荐

  1. python-如何解决python执行pip install 命令的时候出现 File“<stdin>“,line 1 pip install XXX的问题

    python-如何解决python执行pip install 命令的时候出现 File"",line 1 pip install XXX的问题 参考文章: (1)python-如何 ...

  2. python文件输入符_python文件IO与file操作

    1 标准输入输出IO - (1) 打印到屏幕 print() print(self, *args, sep=' ', end='n', file=None): 把传递的表达式 转换成一个 字符串表达式 ...

  3. python中file和open_Python中的file和open简述

    help(file) help(open) 老规矩先看一下内置的帮助文档怎么描述file和open,毕竟官方文档是最直接最准确的描述. Help on class file in module __b ...

  4. windows 安装达梦数据库Python 报错:fatal error C1083: Cannot open include file: ‘DPI.h‘: No such file or direc

    报错: c:\dmdms program\drivers\python\dmpython\strct.h(18): fatal error C1083: Cannot open include fil ...

  5. python udp 大文件_Python UDP服务器发送文本文件的行(Python UDP Server send lines of a text file)...

    Python UDP服务器发送文本文件的行(Python UDP Server send lines of a text file) 我需要模拟一个UDP服务器,它在无限循环中逐行发送文本文件的内容. ...

  6. python中执行py文件出错(提示File “<stdin>”,line 1,SyntaxError:invalid syntax)

    python中执行py文件出错(提示File "<stdin>",line 1,SyntaxError:invalid syntax) 解决办法: 上图中已通过输入py ...

  7. python 报错 SyntaxError: Non-ASCII character ‘\xe6‘ in file E:\PycharmProjects\lianxi\re 111.py on lin

    python 报错 SyntaxError: Non-ASCII character '\xe6' in file E:\PycharmProjects\lianxi\re 111.py on lin ...

  8. mysql-python 安装错误: Cannot open include file: 'config-win.h': No such file or directory

    问题描述: pip instal MySQL-Python 出现如下错误: [plain] view plain copy Installing collected packages: MySql-p ...

  9. _mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h':no such file or directory

    Window7下使用"pip"安装"MySQL-python"提示错误:_mysql.c(42) : fatal error C1083: Cannot ope ...

  10. nltk.stem.WordNetLemmatizer()时报错BadZipFile(“File is not a zip file“)的解决方法

    nltk.stem.WordNetLemmatizer()时报错BadZipFile("File is not a zip file")的解决方法 问题描述 nltk里有个库可以很 ...

最新文章

  1. 奇点云发布三大无人零售终端产品,“云”“端”结合赋能零售商
  2. Android 唯一标识获取
  3. pymysql.err.OperationalError: (1045, “Access denied for user ‘system‘@‘::1‘ (using password: YES)“)
  4. numeric column can contains null
  5. P4590 [TJOI2018]游园会 dp套dp + 状态机
  6. java通过commons-fileupload实现多张图片的上传(jsp页面)
  7. Pro*c源程序中使用宿主结构保存查询结果
  8. php curl跨域cookie_php使用curl带cookie访问一直失败求助
  9. 数据库练习(1)——建立数据库
  10. 数论入门基础(同余定理/费马小定理/扩展欧几里德算法/中国剩余定理)
  11. 实对称矩阵的特征值求法_矩阵论系列——特征值篇
  12. 龙芯2F安装NetBSD
  13. 好用的三维绘图软件CREO学习标注尺寸
  14. 教你如何用ps美化皮肤 每一步都很容易理解!
  15. linux打印机测试程序,轻松了解Linux打印之CUPS软件
  16. python中的screen blit_python pygame blit。获取要显示的图像
  17. 解决无法在哔哩哔哩(b站)上使用HTML5视频播放器脚本插件/油猴等插件失效的问题
  18. C++水电管理信息系统
  19. [水果分级]橘子分级系统 GUI ,源代码,开题报告,橘子图片
  20. webm进度条和修复问题

热门文章

  1. 从IP盗窃知悉:你的知识产权如何被盗?
  2. 记使用sed的一次坑
  3. Bzoj2535 [Noi2010]Plane 航空管制2
  4. oracle共享锁与排他锁 详解
  5. jms两种模式例子-超越昨天的自己系列(2)
  6. 使用RabbitMQ做的一些工作及经验教训
  7. Android 中自定义控件和属性(attr.xml,declare-styleable,TypedArray)的方法和使用 一
  8. 5.支付平台架构:业务、规划、设计与实现 --- 账务系统
  9. 48.Linux/Unix 系统编程手册(下) -- System V 共享内存
  10. 20. 自定义配置文件