16
Your multiuploader form uses python-magic library possibly for filetype identification. However you probably do not have all the missing dependencies installed. Please install the missing dependencies.
29
Go here and then:
For Windoes 32bit, download the file “python_magic_bin-0.4.14-py2.py3-none-win32.whl” and run
pip install python_magic_bin-0.4.14-py2.py3-none-win32.whl
For Windows 64bit, download “python_magic_bin-0.4.14-py2.py3-none-win_amd64.whl” and run
pip install python_magic_bin-0.4.14-py2.py3-none-win_amd64.whl
now python-magic
works
EDIT:
As suggested in the comments, this also works:
pip install python-magic-bin==0.4.14
- [Django]-How to automate createsuperuser on django?
- [Django]-Django Rest Framework with ChoiceField
- [Django]-How to display all model fields with ModelSerializer?
8
As per the documentation (https://pypi.org/project/python-magic/) you have to install libmagic.
For Windows OS, you can do it by run the bellow command:
pip install python-magic-bin
And for Ubuntu based OS, you have to it by the bellow command:
sudo apt-get install libmagic1
From, your exception it is easy to say that, you are using Windows OS, so you have install it by the first command.
- [Django]-How do I package a python application to make it pip-installable?
- [Django]-Django F() division – How to avoid rounding off
- [Django]-How can I run a celery periodic task from the shell manually?
6
As per the documentation the current version of python-magic is 0.4.15
-
You can install the latest released version of python-magic through:
pip install python-magic
-
This will install python-magic-0.4.15 as follows:
C:\Users\username>pip install python-magic Collecting python-magic Using cached https://files.pythonhosted.org/packages/42/a1/76d30c79992e3750dac6790ce16f056f870d368ba142f83f75f694d93001/python_magic-0.4.15-py2.py3-none-any.whl Installing collected packages: python-magic Successfully installed python-magic-0.4.15
-
In the (Windows) documentation it is mentioned:
You’ll need DLLs for libmagic. @julian-r has uploaded a version of this project that includes binaries to pypi: https://pypi.python.org/pypi/python-magic-bin/0.4.14
-
You can install the python-magic-bin 0.4.14 through:
pip install python-magic-bin==0.4.14
-
This will install python-magic-bin 0.4.14 as follows:
C:\Users\username>pip install python-magic-bin==0.4.14 Collecting python-magic-bin==0.4.14 Downloading https://files.pythonhosted.org/packages/5a/5d/10b9ac745d9fd2f7151a2ab901e6bb6983dbd70e87c71111f54859d1ca2e /python_magic_bin-0.4.14-py2.py3-none-win32.whl (397kB) 100% |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 399kB 473kB/s Installing collected packages: python-magic-bin Successfully installed python-magic-bin-0.4.14
-
Sample Code:
import magic print(magic.from_file("C:/Users/username/Desktop/StackOverflow/Google_Gmail.png"))
-
Console Output:
PNG image data, 1366 x 768, 8-bit/color RGB, non-interlaced
- [Django]-How to query Case-insensitive data in Django ORM?
- [Django]-How to get the name of current app within a template?
- [Django]-In the Django admin interface, is there a way to duplicate an item?
1
Install cygwin.
Then move ‘C:\cygwin64\bin\cygmagic-1.dll’ to ‘C:\Windows\System32\magic1.dll’.
- [Django]-Accessing the object in a django admin template
- [Django]-How to reverse the URL of a ViewSet's custom action in django restframework
- [Django]-How do you skip a unit test in Django?
1
- Download cygwin. The version of cygwin must as same as python.(exp: Although your OS is Win7 x64, you still should download 32 bit cygwin because your python is 32 bit).
link: https://www.cygwin.com/ - Install cygwin.
- Enter the path of cygwin and copy cygwin1.dll/cyggcc_s-1.dll/cygmagic-1.dll/cygz.dll to C:\Windows\SysWOW64.
- [Django]-Laravel's dd() equivalent in django
- [Django]-Need to convert a string to int in a django template
- [Django]-You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application
0
I was going carzy with this issue. But finally got a solution to it
Steps
- Uninstall all magic libraries from you system (as you may have tried installing tons of garbage by this time)
- Make sure you are running a python 64 bit version
- Install
pip install python-magic-win64==0.4.13
- very important step, change your import statement to
from winmagic import magic
Enjoy !!!
- [Django]-Django add extra field to a ModelForm generated from a Model
- [Django]-What does error mean? : "Forbidden (Referer checking failed – no Referer.):"
- [Django]-Django startswith on fields
0
If your target platform supports the file
command with certain extensions (available on macOS, *BSD and most Linux variants), you can use the following wrapper that does not require libmagic nor other dependencies:
import contextlib
import subprocess
def file_proc():
args = [
'/usr/bin/file',
'--brief',
'-E',
'--no-dereference',
'--no-buffer',
'--preserve-date',
'-00',
'--mime-type',
'--files-from', '-'
]
with contextlib.ExitStack() as stack:
proc = subprocess.Popen(args, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, preexec_fn=None, text=True)
stack.callback(proc.kill)
while True:
file_path = yield
proc.stdin.write(file_path + '\n')
proc.stdin.flush()
file_type = ''
while (c := proc.stdout.read(1)) != '\0':
file_type += c
yield file_type.splitlines()[0]
@contextlib.contextmanager
def file_typer():
proc = file_proc()
proc.send(None)
def getter(path):
posix_type = proc.send(path.as_posix())
proc.send(None)
return posix_type
with contextlib.closing(proc):
yield getter
with file_typer() as typer:
typer('/usr/bin/python')
See the GitHub enter link description heregist for the most up-to-date version of this script.
- [Django]-What is an efficient way of inserting thousands of records into an SQLite table using Django?
- [Django]-What's the purpose of Django setting ‘SECRET_KEY’?
- [Django]-Alowing 'fuzzy' translations in django pages?