10

I've able to pip install all other packages such as bumpy, sklearn etc. but mnist package throws me error as the following. I've been trying to use sudo pip install but it also says that

applesys$ pip install mnist
Requirement already satisfied: mnist in            /Users/applesys/anaconda3/lib/python3.5/site-packages
Requirement already satisfied: numpy in /Users/applesys/anaconda3/lib/python3.5/site-packages (from mnist)
applesys$ sudo pip install mnist
Password:
The directory '/Users/applesys/Library/Caches/pip/http' or its parent             directory is not owned by the current user and the cache has been disabled.     Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/applesys/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: mnist in    /Users/applesys/anaconda3/lib/python3.5/site-packages
Requirement already satisfied: numpy in /Users/applesys/anaconda3/lib/python3.5/site-packages (from mnist)

import error

7 Answers 7

29

Note that python-mnist and mnist are two different packages, and they both have a module called mnist. The package you want is python-mnist. So do this:

pip install python-mnist

It might be necessary to uninstall the mnist package with:

pip uninstall mnist

Then your import statement should work.

1
  • After installing python-mnist, if still getting error then again restart anaconda and then run the code. Mar 20, 2019 at 1:07
5

As noted by @dinosaur, python-mnist and mnist are two different packages. For python package, python-mnist, the only module is loader.

If you change the import to:

from mnist.loader import MNIST

It should work.

1
  • This AND make sure you're using the python-mnist package, and you may want to uninstall the package mnist Dec 8, 2021 at 23:38
1

You are trying to call a function that is not existing for example

Import time Time.sleep(9)

Here it sleeps for 9 but if you try to call the module from the module

From time import time It will look in time and find a function called time for example

Time.time

In this example the time function is existing so it will work but instead of time.time it will be used as time

Before: current_time = time.time After: current_time = time (Would recommend importing it as a diffrent name example: from time import time as currentime)

So if you are trying to call a function in the module please re-look at the name If you are trying to call the module just do

Import mnist

Or if there is a function inside the module: from mnist import mnist no caps

1

I had the same problem. While inspecting the "mnist" folder that holds the "mnist" module, I could not find "MNIST" in the main module

    __init__.py

However, the MNIST class was found in the "loader.py" file, at the same location. I copied the "loader.py" file to the same folder where my Python script resides (where I'm trying to use this mnist module). Now, instead of using:

    from mnist import MNIST

I used:

    from loader import MNIST

Now everything works fine for me.

1
  • 1
    I was having this problem on a Windows machine. PIP reported back that I was using the latest version of mnist. However, a check at the code available at github.com/sorki/python-mnist revealed that the Windows installation was not up-to-date. I installed the latest github version (python-mnist 0.3) and now all works fine using "from mnist import MNIST".
    – Markacho
    Jul 5, 2017 at 5:43
1

The you are using the wrong mnist code. you must be following lasagne example; they have a file called mnist.py with load_data function. I suggest you go to their example file, copy the code and save as lasagne_mnist.py, so when you import from mnist it will be clear from which mnist you are importing. Remember to have the directory in python path and init.py file in place to recognize it. then you can:

from lasagne_mnist import load_dataset
X_train, y_train, X_valid, y_valid, X_test, y_test = load_dataset()

where it should download the data

1

I am just a beginner to both python and Machine learning.For me it turned out that the python script I was using was also named 'mnist.py' which was causing the error(that's what i think).I am not sure about this but this might help you.

0

The proper way to import the mnist package is to just do:

import mnist

Should work fine - pip installed your packages properly.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.