Import Error: No module called magic yet python-magic is installed
Asked Answered
C

1

12

I am trying to edit some code that uses python-magic but I get an Import Error: No module called magic. Before I looked around the Internet and found advise on installing python-magic using pip which I did. I installed python-magic using pip install python-magic and also did pip install libarchive-c successfully.

when I try to do the import on the python shell. I am able to successfully as below; sc1

But when I try to run code that uses this import statement I get an import error for missing magic module as below; sc2

If anyone knows what is happening. Please help.

Cumquat answered 14/10, 2016 at 17:13 Comment(0)
H
20

You have installed magic for Python 2.7, but Diffoscope uses Python 3 and explicitly recommends the package python3-magic in the repositories, which can be installed with sudo apt-get install python3-magic. Modules installed for Python 2.7 are not necessarily shared with Python 3, so you may need to install both versions if you need it for 2.7 as well.

On Ubuntu, you can run Python 3 with python3 and access Python 3's pip installation with pip3 to ensure that you are using the correct version.

Hopeh answered 14/10, 2016 at 17:19 Comment(2)
Thanks worked like a charm.I decided to make python 3 my default python version. Did sudo apt-get install python3-magic. And stopped getting this error.Cumquat
@alam do you know do i use this in gitpod? i tried adding that to dockerfile and tried installing with brew nothing seems to work.Wicks

© 2022 - 2024 — McMap. All rights reserved.