【问题标题】:ImportError when I try to run a .py script using CherryPy当我尝试使用 CherryPy 运行 .py 脚本时出现 ImportError
【发布时间】:2015-05-28 01:11:15
【问题描述】:

我正在使用 python 2.7 和 cherrypy 3.7,并在 Ubuntu 14.04 上运行它们。

我有一个简单的 hello world 文件,我正在尝试使用以下命令运行:

python HelloWorld.py

这会导致以下错误:

ImportError: 没有名为 cherrypy 的模块

请解释为什么 Python 找不到该模块。

【问题讨论】:

  • 您似乎没有正确安装cherrypy。如果你使用的是 Ubuntu,你可以试试pip install cherrypy。然后发出python -m cherrypy.tutorial.tut01_helloworld 并转到http://127.0.0.1:8080/
  • 我安装了pip,然后输入命令得到: Requirement already meet (use --upgrade to upgrade): cherrypy in /usr/local/lib/python2.7/dist-packages 然后我试了同时输入 'python HelloWorld.py' 和 'python -m cherrypy.tutorial.tut01_helloworld' 并得到与以前相同的 ImportError。
  • 我们不会在此处的问题标题中添加“已解决”。将答案标记为“已接受”就是为了这个目的。

标签: python-2.7 importerror cherrypy


【解决方案1】:

例如,Ubuntu 将拥有 Python 2.6 的本机版本。因此,您需要 python 文件的完整路径。尝试运行它,如果失败,请在您的系统中搜索 python2.7 文件夹。

/usr/local/bin/python2.7 tut01.py

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2013-03-09
    • 1970-01-01
    • 2011-05-12
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多