PermissionError: [Errno 13] Permission denied when doing input_data.read_data_sets(..)

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

I pip installed Tensor Flow so I don't have tensorflow.examples so I got the souce input_data from GitHub. How ever I am getting the following error.

PermissionError: [Errno 13] Permission denied: 'C:\Users\Nikhil\AppData\Local\Temp\tmp5gr8f26y'

This is my code.

import input_data mnist = input_data.read_data_sets("/MNIST_data/", one_hot = True) 

How do I solve this problem? There is another thread dealing with the exact same issue but that solution did not solve my problem. What should I do now? The input_data.py file is in my projects's directory. My project directory looks like this.

tensor_flow           |           tf.py           input_data.py 

I have tried and exhausted all means described in Stack Overflow. Please do not indicate duplicates.

runfile('C:/Users/Nikhil/Desktop/Tensor Flow/tensf.py', wdir='C:/Users/Nikhil/Desktop/Tensor Flow') Traceback (most recent call last):

File "", line 1, in runfile('C:/Users/Nikhil/Desktop/Tensor Flow/tensf.py', wdir='C:/Users/Nikhil/Desktop/Tensor Flow')

File "C:\Users\Nikhil\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile execfile(filename, namespace)

File "C:\Users\Nikhil\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/Nikhil/Desktop/Tensor Flow/tensf.py", line 26, in mnist = input_data.read_data_sets("MNIST_data/", one_hot = True)

File "C:\Users\Nikhil\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\mnist.py", line 211, in read_data_sets SOURCE_URL + TRAIN_IMAGES)

File "C:\Users\Nikhil\Anaconda3\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\base.py", line 141, in maybe_download urllib.request.urlretrieve(source_url, temp_file_name)

File "C:\Users\Nikhil\Anaconda3\lib\urllib\request.py", line 198, in urlretrieve tfp = open(filename, 'wb')

PermissionError: [Errno 13] Permission denied: 'C:\Users\Nikhil\AppData\Local\Temp\tmpry0jmpiu'

回答1:

Ok do this:

Create a directory "MNIST_data" inside this location:

tensorflow/contrib/learn/python/learn/datasets/ 

Copy and extract all of those downloaded files in that folder. This should solve your problem most probably.

I guess the error was that python is unable to open .gz files after downloading.



回答2:

This is the read_data_sets() function:

def read_data_sets(train_dir,                    fake_data=False,                    one_hot=False,                    dtype=dtypes.float32,                    reshape=True,                    validation_size=5000): 

Within this function this code is going to run:

TRAIN_IMAGES = 'train-images-idx3-ubyte.gz' TRAIN_LABELS = 'train-labels-idx1-ubyte.gz' TEST_IMAGES = 't10k-images-idx3-ubyte.gz' TEST_LABELS = 't10k-labels-idx1-ubyte.gz'  local_file = base.maybe_download(TRAIN_IMAGES, train_dir,                                  SOURCE_URL + TRAIN_IMAGES) with open(local_file, 'rb') as f:   train_images = extract_images(f) 

The maybe_download() is downloading the file on your windows temp directory and then trying to access it.

But it is unable to read that file due to restricted permission or some other reason.

So try working on file permissions I guess. I'm on linux or would have tested it for you.

You can do a workaround, download data manually to the current working folder. You can download from here:

TRAIN_IMAGES = 'http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz' TRAIN_LABELS = 'http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz' TEST_IMAGES = 'http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz' TEST_LABELS = 'http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz' 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!