2

In my code, I have a line to open a text file from a directory. When I was using jupyter notebook in Windows 10, it works perfectly.

a = open('C:\\users\\pym\\Desktop\\test\\Data.txt', 'r')

I decided to switch running my codes in Linux. I created a directory on my host machine using mkdir ~/notebooks then, I used docker run -p 8888:8888 -v ~/notebooks:/home/jovyan jupyter/minimal-notebook to mount the directory to the docker container directory. now everything that I do in jupyter notebook saves on that directory.

But when I try to open this file, I get the following error

FileNotFoundError: [Errno 2] No such file or directory: '/home/pym/notebooks/test/Data.txt'

I have used the following line to read the file, and I tested that with slash, backslash, double backslash,..., but no success.

a = open('/home/pym/notebooks/test/Data.txt', 'r')
a = open('\home\pym\notebooks\test\Data.txt', 'r')
a = open('\\home\\pym\\notebooks\\test\\Data.txt', 'r')

anyone knows what is the solution?

  • You need to [mount a volume](https://stackoverflow.com/questions/23439126/how-to-mount-a-host-directory-in-a-docker-container) to access the files from within the docker container. – Anon Coward Mar 08 '21 at 16:30
  • @AnonCoward I created a directory mkdir ~/notebooks on my host machine, then I used docker run -p 8888:8888 -v ~/notebooks:/home/jovyan jupyter/minimal-notebook to mount the directory to the docker container directory. now everything that I do in jupyter notebook saves on that directory. However; it still get the same Error. –  Mar 09 '21 at 15:47

1 Answers1

0

Please open terminal in directory where text file is there. and write pwd command in terminal then enter. it returns the path directory of your text file.

Zeinab Mardi
  • 133
  • 1
  • 5