Forums

Newbie -- confused about import, paths, etc

I have a simple django app. It works fine in the browser. But when I attempt to start an interactive console by typing:

> python manage.py console

I get an error: ImportError: No module named shopify

shopify is an api library that I installed via this command:

pip install --user shopifyAPI

in my models and views, import the shopify package with, simply:

import shopify

And everything works fine. But I can't even start an interactive console. Do I somehow need to let django know about my external library in order to use the interactive console? If so, how do I do that, or where do I learn more about it? I'm a newbie, and I'm kind of lost.

Here's the full error message I get when I try to start a console:

22:35 ~/tsb $ python manage.py shell

Traceback (most recent call last): File "manage.py", line 22, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 367, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 341, in execute django.setup() File "/usr/local/lib/python2.7/dist-packages/django/init.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate app_config.import_models(all_models) File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 199, in import_mod els self.models_module = import_module(models_module_name) File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module import(name) File "/home/cthventures/tsb/barcode/models.py", line 3, in <module> import shopify ImportError: No module named shopify

So I guess my issue is simply that I am not starting the correct version of python. I need to start my shell with: $ python3 manage.py shell and then everything works as expected.

I have a lot to learn!

Glad you figured it out! When you're feeling up to learning (yet another?) new thing, I'd recommend using a virtualenv to install your packages into, and to run your web app. There's more info here: http://help.pythonanywhere.com/pages/VirtualEnvForNewerDjango