installing cPickle with python 3.5

cPickle comes with the standard library… in python 2.x. You are on python 3.x, so if you want cPickle, you can do this: >>> import _pickle as cPickle However, in 3.x, it’s easier just to use pickle. No need to install anything. If something requires cPickle in python 3.x, then that’s probably a bug.

sift = cv2.xfeatures2d.SIFT_create() not working even though have contrib installed

I had the same problem. It seems that SIRF and SURF are no longer available in opencv > 3.4.2.16. I chose an older opencv-python and opencv-contrib-python versions and solved this problem. Here is the history version about opencv-python, and I use the following code : pip install opencv-python==3.4.2.16 pip install opencv-contrib-python==3.4.2.16 Edit For Anaconda User … Read more

Python type hinting without cyclic imports

There isn’t a hugely elegant way to handle import cycles in general, I’m afraid. Your choices are to either redesign your code to remove the cyclic dependency, or if it isn’t feasible, do something like this: # some_file.py from typing import TYPE_CHECKING if TYPE_CHECKING: from main import Main class MyObject(object): def func2(self, some_param: ‘Main’): … … Read more

ImportError: No module named ‘django.core.urlresolvers’

Django 2.0 removes the django.core.urlresolvers module, which was moved to django.urls in version 1.10. You should change any import to use django.urls instead, like this: from django.urls import reverse Note that Django 2.0 removes some features that previously were in django.core.urlresolvers, so you might have to make some more changes before your code works. See … Read more

How to use asyncio with existing blocking library?

There are (sort of) two questions here: first, how to run blocking code asynchronously, and second, how to run async code in parallel (asyncio is single-threaded, so the GIL still applies, so it isn’t truly parallel, but I digress). Concurrent tasks can be created using asyncio.ensure_future, as documented here. To run synchronous code, you will … Read more

Difference between numpy dot() and Python 3.5+ matrix multiplication @

The @ operator calls the array’s __matmul__ method, not dot. This method is also present in the API as the function np.matmul. >>> a = np.random.rand(8,13,13) >>> b = np.random.rand(8,13,13) >>> np.matmul(a, b).shape (8, 13, 13) From the documentation: matmul differs from dot in two important ways. Multiplication by scalars is not allowed. Stacks of … Read more