V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
pjcom
V2EX  ›  Python

新手求救python.....

  •  
  •   pjcom ·
    dadadacai · 2012-06-25 01:06:03 +08:00 · 3986 次点击
    这是一个创建于 4323 天前的主题,其中的信息可能已经有所发展或是发生改变。
    ubuntu下的python问题,如下,不知到如何解决呢?
    dell@ubuntu:~$ python text.py
    python: can't open file 'text.py': [Errno 2] No such file or directory
    dell@ubuntu:~$
    22 条回复    1970-01-01 08:00:00 +08:00
    feiandxs
        1
    feiandxs  
       2012-06-25 01:09:19 +08:00   ❤️ 1
    python ./text.py
    你不带路径系统会去环境变量指定的目录去找,自然找不到。
    fanzeyi
        2
    fanzeyi  
       2012-06-25 01:12:25 +08:00
    @feiandxs 貌似不是这个问题…… 我运行的时候从来没带过 ./

    如果是单独执行一个 chmod +x 的需要 ./ 开头.. 比如 ./a.out 之类的

    // 楼主这是没找到 text.py 这文件啊…… 确定在这个文件存在的目录么?或者文件名打错?
    pjcom
        3
    pjcom  
    OP
       2012-06-25 01:13:20 +08:00
    @feiandxs 泪奔啊~~~太感谢你了,只怪自己太二逼了 哈哈
    evlos
        4
    evlos  
       2012-06-25 01:15:19 +08:00
    奇怪了,我不管在 ubuntu 还是 mac 都不需要 ./ 诶。。
    pjcom
        5
    pjcom  
    OP
       2012-06-25 01:17:00 +08:00
    @fanzeyi 恩~~貌似 ./也不行呢 文件存在呀~难道.....
    feiandxs
        6
    feiandxs  
       2012-06-25 01:18:52 +08:00
    @evlos 如果在当前目录下文件本身是可执行,那么可以不带路径
    直接在文件所在目录执行python xxx.py/ xxx.sh 都可以运行
    如果文件没有加上可执行,那么必须指定路径。
    feiandxs
        7
    feiandxs  
       2012-06-25 01:19:29 +08:00
    @pjcom 给上执行权限试试
    bcxx
        8
    bcxx  
       2012-06-25 01:29:02 +08:00
    先 ls -l 看看= =
    eric_q
        9
    eric_q  
       2012-06-25 01:41:54 +08:00
    @bcxx +1,先把 ls -l 的结果贴一下...
    这个明显就是文件不存在?
    pjcom
        10
    pjcom  
    OP
       2012-06-25 01:44:00 +08:00
    @eric_q -rw-r--r-- 1 dell dell 8445 6月 25 2012 examples.desktop
    drwxrwxr-x 2 dell dell 4096 6月 25 00:24 mystuff
    drwxr-xr-x 2 dell dell 4096 6月 25 2012 公共的
    drwxr-xr-x 2 dell dell 4096 6月 25 2012 模板
    drwxr-xr-x 2 dell dell 4096 6月 25 2012 视频
    drwxr-xr-x 2 dell dell 4096 6月 25 01:02 图片
    drwxr-xr-x 2 dell dell 4096 6月 25 2012 文档
    drwxr-xr-x 2 dell dell 4096 6月 25 2012 下载
    drwxr-xr-x 2 dell dell 4096 6月 25 2012 音乐
    drwxr-xr-x 2 dell dell 4096 6月 25 01:24 桌面
    bcxx
        11
    bcxx  
       2012-06-25 01:46:39 +08:00
    @pjcom 所以就没有 text.py 这个文件咯= = 想想你存在哪里了?
    eric_q
        12
    eric_q  
       2012-06-25 01:46:50 +08:00
    @pjcom
    可见 text.py 并不存在于你的 ~ 目录下。自然无法执行了
    crossd
        13
    crossd  
       2012-06-25 01:46:51 +08:00
    @pjcom 根据你给的结果来看 根本没有text.py

    你找找你的text.py 放在哪里了
    pjcom
        14
    pjcom  
    OP
       2012-06-25 01:51:53 +08:00
    @crossd
    @eric_q
    感谢两位 确实地方放错了 ,,呵呵

    dell@ubuntu:~$ python text.py
    hello world!
    hello again.
    i like typing this.
    this is fun.
    yay!printing.
    i'd much rather you 'not'.
    i"said" do not touch this.
    dell@ubuntu:~$
    eric_q
        15
    eric_q  
       2012-06-25 01:52:39 +08:00
    LPTHW
    kevinzhow
        16
    kevinzhow  
       2012-06-25 01:56:18 +08:00
    囧。我一开始就是怀疑放错地方了,最后还真是。。
    bcxx
        17
    bcxx  
       2012-06-25 01:56:55 +08:00
    @kevinzhow 这不是写着么……
    VeryCB
        18
    VeryCB  
       2012-06-25 02:35:49 +08:00
    @eric_q 我就是看这本书开始学Python的,哈哈~
    reus
        19
    reus  
       2012-06-25 02:40:36 +08:00
    python: can't open file 'text.py': [Errno 2] No such file or directory
    楼主可以理解这行提示的意思么?
    0bit
        20
    0bit  
       2012-06-25 07:04:23 +08:00
    想起了我最近新来的小师妹,遇到问题从来不看错误提示,即使特简单的一句话也不看,直接回头叫我人肉调试,情何以堪啊
    pjcom
        21
    pjcom  
    OP
       2012-06-25 08:55:11 +08:00
    @reus 找不到文件~~~
    pjcom
        22
    pjcom  
    OP
       2012-06-25 08:56:01 +08:00
    @eric_q 是啊 感觉挺好的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1965 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:16 · PVG 00:16 · LAX 09:16 · JFK 12:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.