简体   繁体   中英

Python doesn't work: ImportError: No module named 'logging'

I'm experiencing a very strange issue on my Digitalocean Ubuntu droplet, where Python 2.7 gives me the following error:

  from instagram import InstagramAuthentication, InstagramAPI
  File "/root/instagram_insights/socialgraphs-final-assignment/instagram.py", line 1, in <module>
    import requests
  File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 55, in <module>
    import urllib3
  File "/usr/lib/python2.7/dist-packages/urllib3/__init__.py", line 10, in <module>
    from .connectionpool import (
  File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 2, in <module>
    import logging
ImportError: No module named logging

In fact, I can't do anything with Python:

  1. If I'm trying to reinstall python through apt-get I get the same error
  2. If I'm trying to execute a any pip command, eg pip search logging , I get the error
  3. I can't even create a new virtualenv by doing virtualenv venv without getting the same error

My PYTHONPATH looks like this: ['', '/usr/local/lib/python2.7/dist-packages/gunicorn-19.3.0-py2.7.egg', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages']

The funny thing is that the error appeared out of the blue until I restarted gunicorn, which is the WSGI server I'm using to host my Flask site.

Before it happened I was fiddling with logs in nginx , but I can't see how that should have affected my Python installation.

Make sure you use system-wide python and not virtualenv-from-somewhere:

which python

Try to find out where this module is located:

sudo updatedb
locate logging | grep python

Then try adding this path to PYTHONPATH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM