[英]How to use mock in django?
I tried to install a mock library for django from http://www.voidspace.org.uk/python/mock/ 我试图从http://www.voidspace.org.uk/python/mock/为django安装一个模拟库
But when i type in 但是当我输入时
pip install -U mock
while in virtualenv, and then try to 而在virtualenv,然后尝试
import mock
from django project's shell i get: 从django项目的shell我得到:
ImportError: No module named mock
What can I do? 我能做什么?
Check to see if the module is in the path. 检查模块是否在路径中。 To do this, in the Python shell:
为此,在Python shell中:
>>> import sys
>>> print sys.path
If it was installed correctly, you should see the mock
directory in one of the directories printed out. 如果安装正确,您应该看到打印出的其中一个目录中的
mock
目录。
If you do not find the mock
directory, I'm assuming that pip
is not installing the module in the virtualenv
packages directory. 如果你找不到
mock
目录,我假设pip
没有在virtualenv
包目录中安装模块。
OK, it was my fault. 好的,这是我的错。
I ran shell and tests by: 我运行shell并测试:
./manage.py
instead of 代替
python manage
so my virtualenv directory wasn't included in sys.path, and mock package was unavaible. 所以我的virtualenv目录没有包含在sys.path中,并且mock包是不可用的。 Thanks for help.
感谢帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.