各种坑,用过
pip install python-magic
pip install python-libmagic
pip install python-magic-bin
都不行
直到看到
Name Conflict
There are, sadly, two libraries which use the module name magic
. Both have been around for quite a while. If you are using this module and get an error using a method like open
, your code is expecting the other one. Hopefully one day these will be reconciled.
才知道原来有另一个同名的magic,但是是什么呢?不清楚
直到找到这篇文章
https://stackoverflow.com/questions/43580/how-to-find-the-mime-type-of-a-file-in-python
直到这个好心人mammadori的出现
here are 3 different libraries that wraps libmagic.
2 of them are available on pypi (so pip install will work):
- filemagic
- python-magic
And another, similar to python-magic is available directly in the latest libmagic sources, and it is the one you probably have in your linux distribution.
In Debian the package python-magic is about this one and it is used as toivotuo said and it is not obsoleted as Simon Zimmermann said (IMHO).
It seems to me another take (by the original author of libmagic).
Too bad is not available directly on pypi.
I added a repo for convenience: github.com/mammadori/magic-python that way you can:
pip install -e git://github.com/mammadori/magic-python.git#egg=Magic_file_extensions