我似乎不知道如何将 Stripe 导入到我的 Django 项目中。我正在运行 Python 2.7.3,并且一直收到
NameError at /complete/ global name. 'stripe' is not defined.
即使我只是打开终端然后python
输入
>>> import stripe
我收到:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named stripe
但是,如果我在目录中:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
然后上面的import stripe
命令就成功导入了 Stripe。然而,正如我所说,Django 不知道如何导入 Stripe。问题可能是某处的路径引用吗?我认为这可能是 Python 版本的问题,但无论我输入python2.6
or python2.7
then import stripe
,它仍然无法正常工作,除非我在上面的那个目录中。我是否需要在我的 INSTALLED_APPS 或项目的 settings.py 文件中的某个位置包含条带?
我按照他们的文档安装了 Stripe:
sudo pip install --index-url https://code.stripe.com --upgrade stripe
回应:
Requirement already up-to-date: stripe in ./stripe-1.7.2-py2.7.egg
Requirement already up-to-date: requests>=0.8.8 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from stripe)
Requirement already up-to-date: certifi>=0.0.4 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests>=0.8.8->stripe)
Cleaning up...
在这一点上,我不太确定该怎么做。下面是 Django 回溯。
Environment:
Request Method: POST
Request URL: http://localhost:8000/complete/
Django Version: 1.5.dev20120523102003
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.flatpages',
'django.contrib.admin',
'catalog',
'utils',
'cart',
'checkout')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')
Traceback:
File "/Users/Diepenbrock/django-trunk/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/Diepenbrock/Documents/django_/ecomstore/checkout/views.py" in complete_order
15. stripe.api_key = "wXvAcOY6Rferd6oYNsc7Qi82aMm1KwyP"
Exception Type: NameError at /complete/
Exception Value: global name 'stripe' is not defined
编辑:
import sys
print sys.path
import stripe
返回
['/Users/Diepenbrock/Documents/django_/ecomstore', '/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg', '/Users/Diepenbrock/django-trunk', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages']
根据答案,我也尝试过pip install --index-url https://code.stripe.com --upgrade stripe
这是我收到的:
Requirement already up-to-date: stripe in ./stripe-1.7.2-py2.7.egg
Requirement already up-to-date: requests>=0.8.8 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from stripe)
Requirement already up-to-date: certifi>=0.0.4 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from requests>=0.8.8->stripe)
Cleaning up...