I can't seem to figure out how to import Stripe into my Django project. I'm running Python 2.7.3 and I keep receiving
NameError at /complete/ global name. 'stripe' is not defined.
Even when I just open up Terminal and type python
then
>>> import stripe
I receive:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named stripe
However, if I'm in the directory:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Then the above import stripe
command successfully imports Stripe. However, as I've stated, Django does not know how to import Stripe. Might the issue be a path reference somewhere? I thought it might be a Python version issue, but regardless of whether I type python2.6
or python2.7
and then import stripe
, it still does not work unless I'm in that directory above. Do I need to include stripe in my INSTALLED_APPS or somewhere in my project's settings.py file?
I installed Stripe as per their documentation:
sudo pip install --index-url https://code.stripe.com --upgrade stripe
Which responds with:
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...
At this point, I'm not quite sure what to do. Below is the Django traceback.
Environment:Request Method: POSTRequest 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_response111. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/Diepenbrock/Documents/django_/ecomstore/checkout/views.py" in complete_order15. stripe.api_key = "wXvAcOY6Rferd6oYNsc7Qi82aMm1KwyP"Exception Type: NameError at /complete/
Exception Value: global name 'stripe' is not defined
EDIT:
import sys
print sys.path
import stripe
returns
['/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']
As per an answer, I also tried pip install --index-url https://code.stripe.com --upgrade stripe
This what I received:
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...