首页 \ 问答 \ Python错误 - ImportError:没有名为'webapp2'的模块(Python Error - ImportError: no module named 'webapp2')

Python错误 - ImportError:没有名为'webapp2'的模块(Python Error - ImportError: no module named 'webapp2')

我是Python的初学者,并且在我的机器上本地运行我的python googleppengine代码非常困难。

我的代码如下所示:

    import json
    import urllib
    import os
    import webapp2
    from google.appengine.ext.webapp import template
    import datetime
    from google.appengine.ext import db


    class Events(db.Model):
        venue_name = db.StringProperty()
        address = db.StringProperty()
        id = db.StringProperty()
        venue_id = db.StringProperty()

        # hire_date = db.DateProperty()
        # attended_hr_training = db.BooleanProperty()

    class eventSearch(webapp2.RequestHandler):  
def get(self):
    base_url = 'http://api.eventful.com/json/events/search?app_key=zGtDX6cwQjCRdkf6&l=dublin&?q=music'
    response = urllib.urlopen(base_url)
    html = response.read()
    html = json.loads(html)
    result = html['venues']
    result1 = result['venue']

当我使用命令“python file.py”在cmd提示符下运行此代码时,我收到以下错误:

Traceback <most recent call last>:
File "file.py", line 4, in <module>
import webapp2
ImportError: No module named 'webapp2'

我有1.创建一个PythonPath中建议在如何添加到Windows 7中的pythonpath? 在我的系统变量的目录中:C:\ Python33 \ DLLs; C:\ Python33 \ Lib; C:\ Python33 \ Lib \ lib2to3; C:\ Program Files(x86)\ Google \ google_appengine; C:\ Program Files(x86 )\谷歌\ google_appengine \ lib中;

然后,我也将下面的两个目录添加到我的“PATH”变量中,正如答案中推荐的那样 - 即使我没有安装webapp2,导入webapp2也可以在google-app-engine上运行
C:\ Program Files(x86)\ Google \ google_appengine \; C:\ Program Files(x86)\ Google \ google_appengine \ lib

编辑:在提供的答案中的建议后,我也意识到,GAE不支持3.3版本的Python,我试图在我的问题的前一部分运行它。 在卸载Python33并安装Python27之后,改变我的系统变量以反映新的Python27,我仍然遇到问题,并且我的代码不会与GAE启动器一起上传。 我在我的日志控制台(GAE启动器)中收到以下错误:

2013-04-14 22:59:19 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=8080', '--admin_port=8001', 'C:\\Users\\Karen\\Desktop\\Development\\projects\\file']"
Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 193, in     <module>
    _run_file(__file__, globals())
  File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 189, in _run_file
    execfile(script_path, globals_)
  File "C:\Program Files     (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 30, in <module>
    from google.appengine.datastore import datastore_stub_util
  File "C:\Program Files     (x86)\Google\google_appengine\google\appengine\datastore\datastore_stub_util.py", line 45,     in <module>
    from google.appengine.api import api_base_pb
  File "C:\Program Files     (x86)\Google\google_appengine\google\appengine\api\api_base_pb.py", line 20, in <module>
    from google.net.proto import ProtocolBuffer
  File "C:\Program Files (x86)\Google\google_appengine\google\net\proto\ProtocolBuffer.py", line 22, in <module>
    import httplib
  File "C:\Python27\lib\httplib.py", line 71, in <module>
    import socket
  File "C:\Python27\lib\socket.py", line 47, in <module>
    import _socket
ImportError: Module use of python25.dll conflicts with this version of Python.
2013-04-14 22:59:21 (Process exited with code 1)

感谢您为我提供的任何帮助。


I am a beginner to Python and am having great difficulty in running my python googleppengine code locally on my machine.

My code looks as follows:

import json
import urllib
import os
import webapp2
from google.appengine.ext.webapp import template
import datetime
from google.appengine.ext import db


class Events(db.Model):
    venue_name = db.StringProperty()
    address = db.StringProperty()
    id = db.StringProperty()
    venue_id = db.StringProperty()

    # hire_date = db.DateProperty()
    # attended_hr_training = db.BooleanProperty()

class eventSearch(webapp2.RequestHandler):  
    def get(self):
        base_url = 'http://api.eventful.com/json/events/search?app_key=zGtDX6cwQjCRdkf6&l=dublin&?q=music'
        response = urllib.urlopen(base_url)
        html = response.read()
        html = json.loads(html)
        result = html['venues']
        result1 = result['venue']

When I run this code in my cmd prompt with command "python file.py", I receive the following error:

Traceback <most recent call last>:
File "file.py", line 4, in <module>
import webapp2
ImportError: No module named 'webapp2'

I have 1. Created a PythonPath as suggested in How to add to the pythonpath in Windows? within my system variables with directories: C:\Python33\DLLs;C:\Python33\Lib;C:\Python33\Lib\lib2to3;C:\Program Files (x86)\Google\google_appengine;C:\Program Files (x86)\Google\google_appengine\lib;

I have then also added both of the below directories into my "PATH" variable also, as recommended within answer - import webapp2 works on google-app-engine even though I don't have webapp2 installed
C:\Program Files (x86)\Google\google_appengine\;C:\Program Files (x86)\Google\google_appengine\lib

EDIT: After suggestions within the answers provided I too have realized that GAE does not support version 3.3 of Python I was trying to run it with in my previous part of my question. After uninstalling Python33 and installing Python27 instead, changing my system variables to reflect the new Python27, I am still having issues and my code will not upload with the GAE launcher. I receive the following errors within my log-console (GAE Launcher):

2013-04-14 22:59:19 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=8080', '--admin_port=8001', 'C:\\Users\\Karen\\Desktop\\Development\\projects\\file']"
Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 193, in     <module>
    _run_file(__file__, globals())
  File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 189, in _run_file
    execfile(script_path, globals_)
  File "C:\Program Files     (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 30, in <module>
    from google.appengine.datastore import datastore_stub_util
  File "C:\Program Files     (x86)\Google\google_appengine\google\appengine\datastore\datastore_stub_util.py", line 45,     in <module>
    from google.appengine.api import api_base_pb
  File "C:\Program Files     (x86)\Google\google_appengine\google\appengine\api\api_base_pb.py", line 20, in <module>
    from google.net.proto import ProtocolBuffer
  File "C:\Program Files (x86)\Google\google_appengine\google\net\proto\ProtocolBuffer.py", line 22, in <module>
    import httplib
  File "C:\Python27\lib\httplib.py", line 71, in <module>
    import socket
  File "C:\Python27\lib\socket.py", line 47, in <module>
    import _socket
ImportError: Module use of python25.dll conflicts with this version of Python.
2013-04-14 22:59:21 (Process exited with code 1)

Thank you for any help that you can provide me.


原文:https://stackoverflow.com/questions/15998801
更新时间:2023-11-28 12:11

最满意答案

微软Pex对此有很大的支持。 它对框架内置的接口进行标准测试,检查语义合约。 这是你想要的。 如果你投入3小时学习Pex,你不会后悔。

这是最好的TDD。 先写测试,Pex将适应你的实现,直到发现最后一个错误。 一个空的实现是pex完美测试的。 它会很快找到一个错误,就是这样。

您可以将特定接口的所有常见测试逻辑分解出来。 Pex甚至支持泛型测试,这意味着您可以为IComparer的任意实例编写测试,并说:使用以下类型运行此测试。


Microsoft Pex has great support for that. It has standard tests for framework built-in interfaces in it which check the semantic contract. This is what you want. If you invest 3h of learning Pex you will not regret it.

This is TDD at its best. Write the test first and Pex will adapt to your implementation until the very last bug has been found. An empty implementation is perfectly testable with pex. It will just find an error very quickly, that is all.

You can factor out all your common testing logic for a particular interface. Pex even supports generic tests which means you can write a test for an arbitrary instance of IComparer and say: run this test with the following types.

相关问答

更多
  • Jon正好在这里https://stackoverflow.com/a/12622784/395144 ,你应该把他的回答标记为答案: int ICollection.Count { ... } // compiler error! 由于接口可以有明确的实现,提取基础接口不是向后兼容的(使用基类没有这个问题)。 这就是为什么... Collection : IReadOnlyCollection List : IReadOnlyList Dictionary
  • IQueryable : 直到你真的迭代了这些项目之后,才能执行查询,也许是通过做一个.ToList()或一个foreach 。 这意味着您仍然可以添加过滤器,如Where() 。 扩展IEnumerable IEnumerable : 只有前进的项目列表。 没有通过项目0-3,你不能得到“项目4”。 只读列表,您无法添加或删除它。 仍然可能使用延迟执行(IQueryable仍然是一个IEnumerable)。 IList : 随机访问完整列表 可能完全在记忆中(没有延迟执行,但谁知道确切的类实现这一点?) ...
  • 问自己一个问题:你要测试什么? 你提到了FakeContext和Mocking的上下文 - 为什么要使用这两个? 那些只是不同的方式来做同样的事情 - 提供测试只执行上下文。 还有一个更大的问题 - 假的或嘲笑的上下文或集只有一个结果:你不再测试你的真实代码了。 简单的例子: public interface IContext : IDisposable { IDbSet MyEntities { get; } } public class MyEntity { pu ...
  • 集合通常对DAL返回来说非常有用,因为集合不会隐含地保证订单。 这只是一桶物品。 另一方面,IList确实隐含地保证秩序。 所以我们来到IEnumerable或者IList。 下一个问题是:List对象是否“活”? 即是否连接到数据备份,以便在将项目添加到IList时,会反映在数据库中? 对于LINQ到SQL,情况并非如此。 相反,您应该将实体附加到表中。 所以除非你提供这个额外的接线,一个列表是多余的。 坚持IEnumerable。 Collections are not generally very u ...
  • 微软Pex对此有很大的支持。 它对框架内置的接口进行标准测试,检查语义合约。 这是你想要的。 如果你投入3小时学习Pex,你不会后悔。 这是最好的TDD。 先写测试,Pex将适应你的实现,直到发现最后一个错误。 一个空的实现是pex完美测试的。 它会很快找到一个错误,就是这样。 您可以将特定接口的所有常见测试逻辑分解出来。 Pex甚至支持泛型测试,这意味着您可以为IComparer的任意实例编写测试,并说:使用以下类型运行此测试。 Microsoft Pex has great support for th ...
  • IList的 双向关系: 不支持 。 (因为引入了一个额外的索引列来维护子元素的顺序,子元素不能感知) 订购:是的 类型:IList 重复:允许 在添加元素时:整个集合将被加载以获取索引列值。 避免如果孩子的名单是巨大的。 手袋 双向关系:支持 订购:NO 类型:IList 重复:允许 添加一个元素:只有一次命中数据库。 没有性能问题。 我设置 双向关系:支持 订购:NO 类型:ISet(直到NHibernate 3.0它支持来自Iesi.Collections的接口) 重复: 不允许 添加一个元素:整个集 ...
  • 您可以使用Stack类,它实现ICollection和IEnumerable但不实现ICollection 。 以下是类的定义方式: public class Stack : IEnumerable, IEnumerable, ICollection, IReadOnlyCollection You can use the Stack class, it implements ICollection and IEnumerable but not ...
  • 下面是你为此编写单元测试的方法。 请注意,既然您没有指定使用Mock对象框架,那么我将使用穷人技术,即手工编写的存根和模拟。 如果您使用Moq,还有另一种帮助方法。 需要注意的是,为了简化代码执行,我对扩展方法进行了一些更改,因此测试不会意外地失败。 无论如何,检查任何意外行为都是一个很好的防御性编程实践。 回到测试。 SUT(被测系统) 这就是SUT(系统测试)的样子和支持类型的样子。 (请随时根据您的需要进行修改) public static class MyHtmlHelper { publi ...
  • 我认为其实有两个问题需要回答。 我什么时候需要IEnumerable ? 与其他集合类型和语言不同, IEnumerable的查询是使用惰性评估来执行的。 这意味着您可以在枚举中执行几个相关的查询。 值得注意的是,惰性评估不会与副作用很好地相互作用,因为多个枚举可能会给出不同的结果,所以在使用它时需要记住这一点。 在像C#这样的语言中,惰性评估可能是一个非常强大的工具,但如果你不小心,它也是无法解释的行为的来源。 我什么时候不需要ICollection ? ICollection是一个可变 ...
  • 因为所有集合实现IEnumerable ,所以我们可以使用它来代替TCollection类型参数。 不幸的是,类型推断不知道这一点。 这是我写的代码: public static ILookup ToLookup (this IDictionary> dict) { return dict.SelectMany(p => p.Value.Select (v ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)