Django: ImportError: cannot import name _compare_digest - python

I have installed Django 1.6.5 with PIP and Python 2.7.8 from the website.
I ran django-admin.py startproject test123, switched to test123 directory, and ran the command python manage.py runserver, then i get this:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/conf/__init__.py", line 50, in _setup
self._configure_logging()
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/conf/__init__.py", line 72, in _configure_logging
from django.utils.log import DEFAULT_LOGGING
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/utils/log.py", line 7, in <module>
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/views/debug.py", line 10, in <module>
from django.http import (HttpResponse, HttpResponseServerError,
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/http/__init__.py", line 2, in <module>
from django.http.request import (HttpRequest, QueryDict, UnreadablePostError,
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/http/request.py", line 11, in <module>
from django.core import signing
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/signing.py", line 45, in <module>
from django.utils.crypto import constant_time_compare, salted_hmac
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/utils/crypto.py", line 6, in <module>
import hmac
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py", line 8, in <module>
from operator import _compare_digest as compare_digest
ImportError: cannot import name _compare_digest
Found out that operator is a standard python library. Why cant it not import it?
P.S. I did try it in the command line, I can import the operator module, but I get an error on this statement: from operator import _compare_digest as compare_digest

Followed this SO answer:
Uninstall python.org version of python2.7 in favor of default OS X python2.7
Then changed my .bash_profile Python path to /usr/lib/python for the default OSX python path.
Uninstalled Django and MySQL-Python:
sudo pip uninstall django
sudo pip uninstall MySQL-Python
And then again reinstalled everything, but with MySQL-Python being the first and second Django.
After these steps, everything is working.

I get this error with anaconda as my default python and django1.7 while trying to use startproject.
I deleted the venv and recreated it with
virtualenv -p /usr/bin/python2.7 venv
startproject was working again.

You most likely have another file named operator.py on your PYTHONPATH (probably in the current working directory), which shadows the standard library operator module..
Remove or rename the file.

For those not wanting to switch to Apple's python, simply deleting the virtualenv and rebuilding it worked fine for me.
Tip: Don't forget to pip freeze > requirements.txt first if you aren't already tracking your package requirements. That way you can pip install -r requirements.txt to get up and running again quickly.

Related

ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' for windows

I found 0 topics about this issue for Windows, only for Ubuntu, MAc etc.
When I try to install any package via Pycharm, e.g. urllib, matplotlib, heidi, I get the exact same error message as below.
Project interpreter is Anaconda Python 3.7.
Any idea how this can solved?
Error: Traceback (most recent call last):
File "E:\Download\PROGIK\Charm Community Edition 2018.3.5\helpers\packaging_tool.py", line 73, in run_pip
runpy.run_module(module_name, run_name='__main__', alter_sys=True)
File "E:\Download\PROGIK\Anaconda\lib\runpy.py", line 201, in run_module
mod_name, mod_spec, code = _get_module_details(mod_name)
File "E:\Download\PROGIK\Anaconda\lib\runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "E:\Download\PROGIK\Anaconda\lib\runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "E:\Download\PROGIK\Anaconda\lib\site-packages\pip\__init__.py", line 15, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "E:\Download\PROGIK\Anaconda\lib\site-packages\pip\vcs\subversion.py", line 9, in <module>
from pip.index import Link
File "E:\Download\PROGIK\Anaconda\lib\site-packages\pip\index.py", line 30, in <module>
from pip.wheel import Wheel, wheel_ext
File "E:\Download\PROGIK\Anaconda\lib\site-packages\pip\wheel.py", line 35, in <module>
from pip._vendor.distlib.scripts import ScriptMaker
File "E:\Download\PROGIK\Anaconda\lib\site-packages\pip\_vendor\distlib\scripts.py", line 14, in <module>
from .compat import sysconfig, detect_encoding, ZipFile
File "E:\Download\PROGIK\Anaconda\lib\site-packages\pip\_vendor\distlib\compat.py", line 66, in <module>
from urllib.request import (urlopen, urlretrieve, Request, url2pathname,
ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' (E:\Download\PROGIK\Anaconda\lib\urllib\request.py)
Edit: with pip I have only problem with matplotlib, which is another topic:
Cannot install matplotlib. Fatal error LNK1181, Visual Studio fail
Simply went into packages folder and deleted matplotlib package manually because could not make it display graphs in Jupyter (didnt try in Pycharm). Trying to reinstall it now, hopefully it will fix the issue.
To install packages whithin anaconda environment under Windows10, you should use "Anaconda prompt" (find it in win menu)
It starts (Base) venv by default and installs packages in it. Therefore using Python interpreter distributed with Anaconda you will be able to import them with no side actions.
Besides matplotlib is installed there by default

Scrapy - Error while creating project - DDL Load failed

I am trying for a longer time.Please do help.
I installed scrapy using conda.
I tested pip show scrapy in the command line and it is working perfectly.
While i type import scrapy in the python terminal it is not showing any error.
But if i create a project or execute an existing project of scrapy i get the following error:
C:\Users\Nikeshh\Anaconda2\lib\site-packages\scrapy\commands\deploy.py:16: ScrapyDeprecationWarning: Module `scrapy.command` is deprecated, use `scrapy.commands` instead
from scrapy.command import ScrapyCommand
Traceback (most recent call last):
File "C:\Users\Nikeshh\Anaconda2\Scripts\scrapy-script.py", line 10, in <module>
sys.exit(execute())
File "C:\Users\Nikeshh\Anaconda2\lib\site-packages\scrapy\cmdline.py", line 149, in execute
cmd.crawler_process = CrawlerProcess(settings)
File "C:\Users\Nikeshh\Anaconda2\lib\site-packages\scrapy\crawler.py", line 252, in __init__
log_scrapy_info(self.settings)
File "C:\Users\Nikeshh\Anaconda2\lib\site-packages\scrapy\utils\log.py", line 149, in log_scrapy_info
for name, version in scrapy_components_versions()
File "C:\Users\Nikeshh\Anaconda2\lib\site-packages\scrapy\utils\versions.py", line 35, in scrapy_components_versions
("pyOpenSSL", _get_openssl_version()),
File "C:\Users\Nikeshh\Anaconda2\lib\site-packages\scrapy\utils\versions.py", line 43, in _get_openssl_version
import OpenSSL
File "C:\Users\Nikeshh\Anaconda2\lib\site-packages\OpenSSL\__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "C:\Users\Nikeshh\Anaconda2\lib\site-packages\OpenSSL\crypto.py", line 16, in <module>
from OpenSSL._util import (
File "C:\Users\Nikeshh\Anaconda2\lib\site-packages\OpenSSL\_util.py", line 6, in <module>
from cryptography.hazmat.bindings.openssl.binding import Binding
File "C:\Users\Nikeshh\Anaconda2\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 13, in <module>
from cryptography.hazmat.bindings._openssl import ffi, lib
ImportError: DLL load failed: The operating system cannot run %1.
I am using scrapy startproject tutorial to create a project.How to solve this error?
Is there any specific way to execute the scrapy code?
Even when i add openssl using conda i am getting the same error
It looks like you need the OpenSSL libraries that are used for encryption.
You could go and download these from somewhere here: https://wiki.openssl.org/index.php/Binaries
Alternatively I think the installer for git will install OpenSSL by default, which you can get here: https://git-scm.com/download
However, since you're using Anaconda, OpenSSL should also be available with conda: https://anaconda.org/anaconda/openssl
Hope this helps!

Getting AssertionError message installing pip on windows 10

After having downloaded get-pip.py attempting to install, and opening cmd window in windows 10 I am getting the following error message when I type pip and hit enter:
Microsoft Windows [Version 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\Users\adamh>pip
Traceback (most recent call last):
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\Scripts\pip.exe\__main__.py", line 5, in <module>
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\pip\__init__.py", line 26, in <module>
from pip.utils import get_installed_distributions, get_prog
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\pip\utils\__init__.py", line 27, in <module>
from pip._vendor import pkg_resources
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 70, in <module>
from pip._vendor import appdirs
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\pip\_vendor\appdirs.py", line 510, in <module>
import win32com.shell
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\win32com\__init__.py", line 6, in <module>
import pythoncom
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\pythoncom.py", line 2, in <module>
import pywintypes
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\win32\lib\pywintypes.py", line 124, in <module>
__import_pywin32_system_module__("pywintypes", globals())
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\win32\lib\pywintypes.py", line 117, in __import_pywin32_system_module__
assert sys.modules[modname] is not old_mod
AssertionError
C:\Users\adamh>
I tried all of the upgrades and such but none of them have been successful. Thank you very much for any help provided. Sincerely, will_learn
First Check if your python is running is properly from command prompt.
Open command prompt and run python it should show your python version else install it properly and add its path in environment variables
Mostly Pip should be already included in Python 2.7.9+ or 3.4+, but if for whatever reason it is not there, you can use the following one-liner.
Download https://bootstrap.pypa.io/get-pip.py and run it with Administrator permission python get-pip.py (If you are on Linux, use sudo python get-pip.py)
You must to add pip's path into Environment Variables. Pip is contained in python's script directory.
Example my case: C:\Python35\Scripts\pip.exe
To add path to environment variables.
Hold Win and press Pause.
Click Advanced System Settings.
Click Environment Variables.
Add C:\Python35\Scripts (Sorry I don't know name of python 3.5's directory) to the Path on System variables.
Restart Command Prompt.
Edit
In another way, you can use pip-Win instead of pip. Read more here: https://sites.google.com/site/pydatalog/python/pip-for-windows

Cannot install virtualenv using pip

I first installed distribute, then pip with easy_install but when I run:
sudo pip install virtualenv
I get these error messages:
Traceback (most recent call last):
File "/usr/bin/pip", line 8, in ? sys.exit(
File "/usr/lib/python2.4/site-packages/distribute-0.6.49-py2.4.egg/pkg_resources.py", line 345, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.4/site-packages/distribute-0.6.49-py2.4.egg/pkg_resources.py", line 2381, in load_entry_point
return ep.load()
File "/usr/lib/python2.4/site-packages/distribute-0.6.49-py2.4.egg/pkg_resources.py", line 2087, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/lib/python2.4/site-packages/pip-1.4-py2.4.egg/pip/__init__.py", line 10, in ?
from pip.util import get_installed_distributions, get_prog
File "/usr/lib/python2.4/site-packages/pip-1.4-py2.4.egg/pip/util.py", line 17, in ?
from pip.vendor.distlib import version
File "/usr/lib/python2.4/site-packages/pip-1.4-py2.4.egg/pip/vendor/__init__.py", line 8
from __future__ import absolute_importSyntaxError: from __future__ imports must occur at the beginning of the file
I do not know what to do to install virtualenv properly now?
You appear to be using Python 2.4 - try creating the virtualenv with a version of Python which includes from __future__ import absolute_import (Python 2.5 or later).
You can specify which Python to use like this:
virtualenv -p /usr/bin/python2.7

Django throws an ImportError on Mac OS X

I'm trying to get a work project that I git-cloned from work (used in numerous other places, I know the project works fine) to run on my MacBook. I installed Django (via sudo python setup.py install), as well as MySQL, the Python MySQL wrapper, and also virtualenv with virtualenvwrapper.
After creating a virtualenv for my project (virtualenv is created fine), and doing a pip install for the project requirements (all of which install into the proper virtualenv directory), an attempt to do a runserver command spits out the following:
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 436, in execute_manager
setup_environ(settings_mod)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 419, in setup_environ
project_module = import_module(project_name)
File "/Library/Python/2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named website-backend
First try to import this library from python or ./manage.py shell.
If that fails import sys and check if your lib is in sys path print sys.path

Categories