IOError: [Errno 13] Permission denied: How to fix it?

IOError: [Errno 13] Permission denied: How to fix it?

我正在尝试 运行 教程中的以下代码,但出现错误。根据其他帖子,这似乎是一个权限问题(?)。我读过有关 chmod 777 解决方案的信息,但我不确定具体如何实施。我正在 Mac 和 运行 在 Rodeo Python IDE.

中使用以下代码
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()

>>> X_train, y_train, X_val, y_val, X_test, y_test = load_dataset()
Downloading MNIST dataset...

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

<ipython-input-51-554e12c9ff6c> in load_dataset()
      4     if not os.path.exists(filename):
      5         print("Downloading MNIST dataset...")
----> 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
---> 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:
--> 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.
>>> print os.getcwd()
/

您似乎正试图将文件保存到您的根 (/) 目录中,您可能在那里没有权限。将其保存到其他地方。