IOError: [Errno 13] Permission denied: How to fix it?
<p>I'm trying to run the following code from a tutorial, but get an error. Based on other posts, it seems like this is a permissions problem (?). I've read about a chmod 777 solution, but I'm not sure how exactly to implement it. I am working on a Mac and running the following code in the Rodeo Python IDE.</p>

<pre><code>def load_dataset():
    url = 'http://deeplearning.net/data/mnist/mnist.pkl.gz'
    filename = 'mnist.pkl.gz'
    if not os.path.exists(filename):
        print("Downloading MNIST dataset...")
        urlretrieve(url, filename)
    with gzip.open(filename, 'rb') as f:
        data = pickle.load(f)
    X_train, y_train = data[0]
    X_val, y_val = data[1]
    X_test, y_test = data[2]
    X_train = X_train.reshape((-1, 1, 28, 28))
    X_val = X_val.reshape((-1, 1, 28, 28))
    X_test = X_test.reshape((-1, 1, 28, 28))
    y_train = y_train.astype(np.uint8)
    y_val = y_val.astype(np.uint8)
    y_test = y_test.astype(np.uint8)
    return X_train, y_train, X_val, y_val, X_test, y_test

X_train, y_train, X_val, y_val, X_test, y_test = load_dataset()

&gt;&gt;&gt; X_train, y_train, X_val, y_val, X_test, y_test = load_dataset()
Downloading MNIST dataset...

---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
&lt;ipython-input-55-b5dfc0ed9477&gt; in &lt;module&gt;()
----&gt; 1 X_train, y_train, X_val, y_val, X_test, y_test = load_dataset()

&lt;ipython-input-51-554e12c9ff6c&gt; in load_dataset()
      4     if not os.path.exists(filename):
      5         print("Downloading MNIST dataset...")
----&gt; 6         urlretrieve(url, filename)
      7     with gzip.open(filename, 'rb') as f:
      8         data = pickle.load(f)

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.pyc in urlretrieve(url, filename, reporthook, data, context)
     96     else:
     97         opener = _urlopener
---&gt; 98     return opener.retrieve(url, filename, reporthook, data)
     99 def urlcleanup():
    100     if _urlopener:

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.pyc in retrieve(self, url, filename, reporthook, data)
    247             headers = fp.info()
    248             if filename:
--&gt; 249                 tfp = open(filename, 'wb')
    250             else:
    251                 import tempfile

IOError: [Errno 13] Permission denied: 'mnist.pkl.gz'

## I'm guessing this means I'm in the root directory.
&gt;&gt;&gt; print os.getcwd()
/
</code></pre>