python路径问题? “python2.5:无法打开文件“dev_appserver.py”:[Errno 2]没有这样的文件或目录”

发布于 2024-08-31 11:00:40 字数 1083 浏览 8 评论 0原文

我将这一行添加到我的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

屋檐 2024-09-07 11:00:40

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".

爱的故事 2024-09-07 11:00:40

在执行

$ python2.5 dev_appserver.py guestbook/

操作时,传递给可执行文件 python2.5 的是 CURRENT_PATH/dev_appserver.py

您必须使用

$ python /opt/google_appengine/dev_appserver.py guestbook/

or

$ dev_appserver.py guestbook/

来执行,如果 dev_appserver.py 有一个 shebang< /a> 对于 Python,即, 正如 Nick Johnson 指出的#!/usr/bin/env python2.5#!/usr/bin/env python

除非你有充分的理由,否则不要过度指定 python 版本,使用通用的 python 命令,这是最新版本的符号链接。

When doing

$ python2.5 dev_appserver.py guestbook/

what you are passing to the executable python2.5 is CURRENT_PATH/dev_appserver.py.

You have to execute using

$ python /opt/google_appengine/dev_appserver.py guestbook/

or

$ dev_appserver.py guestbook/

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文