python路径问题? “python2.5:无法打开文件“dev_appserver.py”:[Errno 2]没有这样的文件或目录”
我将这一行添加到我的 .bashrc (Ubuntu 9.10)中:
export PYTHONPATH=/opt/google_appengine/
然后我在 Ubuntu 上通过 python2.5 运行 dev_appserver,如下所示:
$ python2.5 dev_appserver.py guestbook/
python2.5: can't open file 'dev_appserver.py': [Errno 2] No such file or directory
正如你所看到的,它无法找到 dev_appserver.py
即使它位于我的 /opt/google_appengine/
目录中。只是为了确保这不是权限问题,我这样做了:
sudo chmod a+rwx dev_appserver.py
为了检查它是否已添加到 python2.5 的系统路径中,我这样做了:
$ python2.5
Python 2.5.5 (r255:77872, Apr 29 2010, 23:59:20)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for line in sys.path: print line
...
/usr/local/lib/python2.5/site-packages/setuptools-0.6c9-py2.5.egg
/opt/google_appengine/demos
/opt/google_appengine
/usr/local/lib/python25.zip
...
该目录显示在这个列表中,所以我不明白为什么它不能当我输入时发现:
$ python2.5 dev_appserver.py guestbook/
我是Python新手,所以我将不胜感激。谢谢。
I added this line to my .bashrc (Ubuntu 9.10):
export PYTHONPATH=/opt/google_appengine/
And then I ran the dev_appserver through python2.5 on Ubuntu like this:
$ python2.5 dev_appserver.py guestbook/
python2.5: can't open file 'dev_appserver.py': [Errno 2] No such file or directory
As you can see, it can't find dev_appserver.py
even though it's in my /opt/google_appengine/
directory. Just to make sure it's not a permissions issue I did this:
sudo chmod a+rwx dev_appserver.py
To check whether it's been added to the system path for python2.5 I did this:
$ python2.5
Python 2.5.5 (r255:77872, Apr 29 2010, 23:59:20)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for line in sys.path: print line
...
/usr/local/lib/python2.5/site-packages/setuptools-0.6c9-py2.5.egg
/opt/google_appengine/demos
/opt/google_appengine
/usr/local/lib/python25.zip
...
The directory shows up in this list so I don't understand why it can't be found when I type:
$ python2.5 dev_appserver.py guestbook/
I'm new to Python so I would appreciate any help. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Python 在查找您在命令行上命名的脚本时不会遵守 PYTHONPATH。您需要提供 dev_appserver.py 的完整路径,或者修改 dev_appserver.py(和其他工具)的第一行以“
#!/usr/bin/env python2.5
”开头。Python doesn't observe PYTHONPATH when looking for a script you name on the command line. You either need to supply the complete path to dev_appserver.py, or modify the first line of dev_appserver.py (and other tools) to start with "
#!/usr/bin/env python2.5
".在执行
操作时,传递给可执行文件
python2.5
的是CURRENT_PATH/dev_appserver.py
。您必须使用
or
来执行,如果
dev_appserver.py
有一个 shebang< /a> 对于 Python,即, 正如 Nick Johnson 指出的,#!/usr/bin/env python2.5
或#!/usr/bin/env python
。除非你有充分的理由,否则不要过度指定 python 版本,使用通用的 python 命令,这是最新版本的符号链接。
When doing
what you are passing to the executable
python2.5
isCURRENT_PATH/dev_appserver.py
.You have to execute using
or
if
dev_appserver.py
has a shebang for Python, that is, as Nick Johnson points out,#!/usr/bin/env python2.5
or#!/usr/bin/env python
.Unless you have a very good reason, don't over specify the python version, use the generic
python
command, that is a symlink to the latest version.