Forums

ImportError: No module named anyjson

Hi, I am working on Gmail API. When I run my code it tries to import simplejson from oauth2client.anyjson and gives me an error "ImportError: No module named anyjson". But I found anyjson within the list of installed packages using "pip list". What could be the problem?

Are you using a virtualenv? Also, are you sure you're using the same Python version for your code and for the pip command? Both python and pip use Python version 2.7 -- if you want to use a different version, just use (eg.) python3.4 or pip3.4.

I'm using python 2.7 and I'm not using virtualenv. Do I need to use it? The same code is working on my local machine.

There's no need to use a virtualenv, I was just asking to make sure that wasn't the problem. How did you install anyjson? It's not part of our default setup.

Also, I'm a bit unclear on why you're importing from oauth2client.anyjson -- shouldn't it just be import anyjson?

pip install --user anyjson I also upgraded it by adding --upgrade. It says "Requirement already up-to-date: anyjson in ./.local/lib/python2.7/site-packages"

This is my error:

Traceback (most recent call last):
  File "Mohini/bo_v3_main.py", line 22, in <module>
    from mail import send_message
  File "/home/AshishPathak/Mohini/mail.py", line 9, in <module>
    from quickstart import gmail_service
  File "/home/AshishPathak/Mohini/quickstart.py", line 6, in <module>
    from apiclient.discovery import build
  File "/usr/local/lib/python2.7/dist-packages/apiclient/discovery.py", line 52, in <module>
    from apiclient.errors import HttpError
  File "/usr/local/lib/python2.7/dist-packages/apiclient/errors.py", line 27, in <module>
    from oauth2client.anyjson import simplejson
ImportError: No module named anyjson

It's getting automatically imported from oauthclient.

[edited by admin: formatting]

Interesting. apiclient isn't trying to import the anyjson package you have installed, it's trying to import oauth2client's private copy of it.

What do you get if you run this in a Python 2.7 console?

from oauth2client.anyjson import simplejson

It's showing the same error :

Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named anyjson

Did you install oauth2client yourself? What version do you have? (I think the only way to find out is to print oauth2client.__version__ from a Python console where you've imported it.)

oauth2client (1.4.7) Yes I did it myself while installing google-api-python-client.

It sounds to me like the version of oauthclient you've installed is not compatible with the version of apiclient. Try installing version 1.1 (which is the same as our system-installed version) and it should work.

.

Could you please give me the exact version number of the package? Also I looked into the list of installed packages on https://www.pythonanywhere.com/batteries_included/#a_python27 but I could not find oauth2client in it.

hi Ashish.

I think Giles is saying that you should try chging your version of oauth2client to 1.1.

The batteries included list is only updated during each deploy (~once a month).

14:11 ~ $ pip install --user oauth2client-1.1 Collecting oauth2client-1.1 /home/AshishPathak/.local/lib/python2.7/site-packages/pip/vendor/requests/packages/urllib3/util/ssl.py:79: InsecurePlatformWarning: A true SSLCont ext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more inform ation, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Could not find a version that satisfies the requirement oauth2client-1.1 (from versions: ) No matching distribution found for oauth2client-1.1 14:12 ~ $

I'm getting this error when I try to install oauth2client version 1.1

oh. that's because you want to do pip install --user oauth2client==1.1 instead

still not working.

How?

according to this link anyjson has been removed from google api, so run this command to upgrade to a newer package: pip install --user --upgrade google-api-python-client

Hi,

I am trying to deploy and publish a small app, I am doing this by referencing a tutorial on Djangogirls.com; I am getting a 'module not found error' following is the extract of the error log. I am new to Django and doing this for the first time, Kindly help me. Thanks

2016-09-24 12:49:38,038 :Error running WSGI application Traceback (most recent call last): File "/bin/user_wsgi_wrapper.py", line 154, in call app_iterator = self.app(environ, start_response) File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application raise e File "/bin/user_wsgi_wrapper.py", line 154, in call app_iterator = self.app(environ, start_response) File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application raise e File "/bin/user_wsgi_wrapper.py", line 154, in call app_iterator = self.app(environ, start_response) File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application raise e File "/bin/user_wsgi_wrapper.py", line 179, in <module> application = load_wsgi_application() File "/bin/user_wsgi_wrapper.py", line 175, in load_wsgi_application return import(os.environ['WSGI_MODULE'], globals(), locals(), ['application']).application File "/var/www/ravindranene_pythonanywhere_com_wsgi.py", line 18, in <module> application = StaticFilesHandler(get_wsgi_application()) File "/home/ravindranene/my-first-blog/myvenv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application django.setup() File "/home/ravindranene/my-first-blog/myvenv/lib/python3.5/site-packages/django/init.py", line 17, in setup configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) File "/home/ravindranene/my-first-blog/myvenv/lib/python3.5/site-packages/django/conf/init.py", line 55, in getattr self._setup(name) File "/home/ravindranene/my-first-blog/myvenv/lib/python3.5/site-packages/django/conf/init.py", line 43, in _setup self._wrapped = Settings(settings_module) File "/home/ravindranene/my-first-blog/myvenv/lib/python3.5/site-packages/django/conf/init.py", line 99, in init mod = importlib.import_module(self.SETTINGS_MODULE) File "/home/ravindranene/my-first-blog/myvenv/lib/python3.5/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: No module named 'mysite'

It's trying to get a file at /home/ravindranene/my-first-blog/mysite/settings.py

Do you have that file?

Hi,

Thanks very much for looking into this. Yes, all the files are present on respective path, following is the tree structure:

my-first-blog
├── README.md
├── __init__.py
├── blog
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-35.pyc
│   │   ├── admin.cpython-35.pyc
│   │   └── models.cpython-35.pyc
│   ├── admin.py
│   ├── apps.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── __init__.py
│   │   └── __pycache__
│   │       ├── 0001_initial.cpython-35.pyc
│   │       └── __init__.cpython-35.pyc
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── db.sqlite3
├── manage.py
└── mysite
    ├── __init__.py
    ├── __pycache__
    │   ├── __init__.cpython-35.pyc
    │   ├── settings.cpython-35.pyc
    │   ├── urls.cpython-35.pyc
    │   └── wsgi.cpython-35.pyc
    ├── settings.py
    ├── urls.py
    └── wsgi.py

[edited by admin: formatting]

Seems like you changed your django settings module setting?

os.environ['DJANGO_SETTINGS_MODULE'] = '/home/my-first-blog/myvenv/my-first-blog/mysite.settings'

change it back to

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

That together with the path stuff above makes it /home/ravindranene/my-first-blog/mysite/settings.py