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
もpython2.7
、を入力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...