I can use ~
instead of /home/username/
to point to a file path when, for example, unzipping a .zip
file.
However, today when I followed the same way to run a RNN example in terminal, tensorflow.python.framework.errors_impl.NotFoundError
was thrown.
$ python ptb_word_lm.py --data_path=~/anaconda2/lib/python2.7/site-packages/tensorflow/models-master/tutorials/rnn/simple-examples/data/ --model=small
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
Traceback (most recent call last):
File "ptb_word_lm.py", line 374, in <module>
tf.app.run()
File "/home/hok/anaconda2/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 44, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "ptb_word_lm.py", line 321, in main
raw_data = reader.ptb_raw_data(FLAGS.data_path)
File "/home/hok/anaconda2/lib/python2.7/site-packages/tensorflow/models-master/tutorials/rnn/ptb/reader.py", line 73, in ptb_raw_data
word_to_id = _build_vocab(train_path)
File "/home/hok/anaconda2/lib/python2.7/site-packages/tensorflow/models-master/tutorials/rnn/ptb/reader.py", line 34, in _build_vocab
data = _read_words(filename)
File "/home/hok/anaconda2/lib/python2.7/site-packages/tensorflow/models-master/tutorials/rnn/ptb/reader.py", line 30, in _read_words
return f.read().decode("utf-8").replace("\n", "<eos>").split()
File "/home/hok/anaconda2/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py", line 106, in read
self._preread_check()
File "/home/hok/anaconda2/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py", line 73, in _preread_check
compat.as_bytes(self.__name), 1024 * 512, status)
File "/home/hok/anaconda2/lib/python2.7/contextlib.py", line 24, in __exit__
self.gen.next()
File "/home/hok/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/errors_impl.py", line 469, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.NotFoundError: ~/anaconda2/lib/python2.7/site-packages/tensorflow/models-master/tutorials/rnn/simple-examples/data/ptb.train.txt
Then I replaced ~
with /home/username/
, and it worked properly.
Why couldn't I use ~
instead of /home/username/
to point to the file path when runing a RNN example?
Could you tell me in detail?
~
before the argument is passed to python? Just like the shell would expand backslash escapes in the path, or remove quotes if the path was quoted. – micheal65536 Mar 08 '17 at 14:17$VARIABLES
, the~
is only expanded at the beginning of a string. – alexis Mar 08 '17 at 14:54exec
'd) should be widely available in UNIX tools. – Charles Duffy Mar 08 '17 at 16:10echo ~
andpython ~
will both expand the argument in precisely the same way, andecho --foo=~
andpython --foo=~
will both fail to expand in exactly the same way, but "it's like everything is quoted with single quotes" reads as if Python somehow suppresses shell expansion behavior that would otherwise happen pre-invocation. – Charles Duffy Mar 08 '17 at 16:12