I'm having this error for the last 2 days. It seems a problem with python requests library, but I've re-installed it several times with no luck.
Traceback (most recent call last):
File "project-src/bla-blah/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "project-src\env\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "project-src\env\lib\site-packages\django\core\management\__init__.py", line 354, in execute
django.setup()
File "project-src\env\lib\site-packages\django\__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "project-src\env\lib\site-packages\django\apps\registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "project-src\env\lib\site-packages\django\apps\config.py", line 112, in create
mod = import_module(mod_path)
File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "project-src\env\lib\site-packages\social\apps\django_app\__init__.py", line 14, in <module>
from social.apps.django_app.utils import load_strategy
File "project-src\env\lib\site-packages\social\apps\django_app\utils.py", line 12, in <module>
from social.backends.utils import get_backend
File "project-src\env\lib\site-packages\social\backends\utils.py", line 2, in <module>
from social.backends.base import BaseAuth
File "project-src\env\lib\site-packages\social\backends\base.py", line 1, in <module>
from requests import request, ConnectionError
File "project-src\env\lib\site-packages\requests\__init__.py", line 58, in <module>
from . import utils
File "project-src\env\lib\site-packages\requests\utils.py", line 24, in <module>
from . import certs
ImportError: cannot import name 'certs'
Maybe it's a problem with Windows 7 update from 2 days ago, because is the only thing that has changed in the last few days.
By the way, I'm using python 3.4 with virtualenv, PyCharm 3.4.1 IDE and Win7.
Inside certs.py there is the code that has the problem (last line):
try:
from certifi import where
except ImportError:
def where():
"""Return the preferred certificate bundle."""
# vendored bundle inside Requests
return os.path.join(os.path.dirname(__file__), 'cacert.pem')
If the error occurs due to a circular dependency, it can be resolved by moving the imported classes to a third file and importing them from this file. If the error occurs due to a misspelled name, the name of the class in the Python file should be verified and corrected.
The Python "ImportError: cannot import name" occurs when we have circular imports (importing members between the same files). To solve the error, move the objects to a third file and import them from a central location in other files, or nest one of the imports in a function.
This worked for me (re-install requests library):
pip uninstall requests
pip install requests
I had also the same problem last week on my Mac (Sierra). Besides, the certs.py
module exists, which means that's a problem somehow related to the OS and not to Python itself. In my case, it was a problem of the max files limits, So just increase it with ulimit 200000 200000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With