我正在尝试从教程中运行以下代码,但收到错误。基于其他帖子,似乎这是一个权限问题(?)。我已经阅读了关于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()
/
答案 0 :(得分:1)
看起来您正在尝试将文件保存到根目录(<link rel="stylesheet" type="text/css" href="https://bootswatch.com/bower_components/bootstrap/dist/css/bootstrap.min.css" />
<div>
<a href="#" class="previous"></a>
<h1>Hello</h1>
<a href="#">
<span id="now">title 1</span>
</a>
<a href="#" class="next">
<a href="#"></a>
<span>title 2</span>
</a>
<a href="#" class="next"></a>
<a href="#">
<span>title 3</span>
</a>
<a href="#" class="next"></a>
<a href="#">
<span>title 4</span>
</a>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
)中,并且您可能没有权限。把它保存到其他地方。