FileNotFoundError in JupyterLab (https://jupyter.org/try-jupyter/lab/) - jupyter-lab

Has anybody faced a FileNotFoundError in JupyterLab (https://jupyter.org/try-jupyter/lab/) when trying to read a .csv file? The file was uploaded in the same directory. I have used a CopyPath option to be sure that the path is correct. Still not working. Any suggestions on how can I fix this?
here is a snapshot of a simple code and an error

This is unlikely to be an error with Jupyter.
Make sure that the ReadFile.ipynb and theFile.csv are in the same directory. If they are not, use a relative import.
If this still doesn't work, try the following synthax. This is independent of the path you provide.
pd.read_csv(r'C:\Users\aiLab\Desktop\example.csv')
Here r is a special character and means raw string. So prefix it to your string literal.
https://www.journaldev.com/23598/python-raw-string:
Python raw string is created by prefixing a string literal with ‘r’ or
‘R’. Python raw string treats backslash () as a literal character.
This is useful when we want to have a string that contains backslash
and don’t want it to be treated as an escape character.
See: pandas.read_csv FileNotFoundError: File b'\xe2\x80\xaa<etc>' despite correct path
Also, make sure that you don't have unwittingly copied an invisible character.

I ran into the same problem.
Make sure your working directory is the same as your notebook and .csv file. Check this by running pwd. You can run ls to get the list of files in the working directory.
If this helps you find the problem, try shutting down the running kernel completely and attaching a new one. This will change the working directory.

Related

How can Python be forced to use raw string equivalent of variable-stored paths on Windows?

It might seem that this question has been asked hundreds of times, but reading every variant of it, it's clear it has never been fully answered, at least not in the context I am experiencing.
I have a filename variable that is being obtained through a dialog (in Blender), and I need to both use the file name and iterate over its directory. The problem is that Python cannot properly convert the backslashes to forward slashes.
Here is the filename: 'D:\scans\testing\2021_12_01_14_41_38\frame_00000.json'
Storing this in a variable yields 'D:\scans\testing\x821_12_01_14_41_38\x0crame_00000.json'.
In other words, once the dialog passes the filename to the variable, nothing more can be done with it. The file itself may be opened, but attempting any other operation on it automatically converts the escape characters.
Here are some other approaches I have tried:
Attempting a find replace using filename.replace('\\','/') yields 'D:/scans\testing\x821_12_01_14_41_38\x0crame_00000.json'.
Using pathlib.Path(filename) yields a WindowsPath object:
WindowsPath('D:/scans\testing\x821_12_01_14_41_38\x0crame_00000.json')
All I need is the directory and the file separated, but even os.path.basename yields
'testing\x821_12_01_14_41_38\x0crame_00000.json'.
Even trying repr(filename) is to no avail. It yields "'D:\\scans\\testing\x821_12_01_14_41_38\x0crame_00000.json'"
re.sub('\\\\','/',filename) yields 'D:/scans\testing\x821_12_01_14_41_38\x0crame_00000.json'
It's mind boggling that such a simple operation on Windows is so complicated, as I have done it millions of times on Linux (yes, I know). Unfortunately, I cannot use the raw string method (r'string') because this is a variable, not a string. I have seen crazy ideas out there such as r'{}'.format(variable), but that doesn't work for obvious reasons.
I could list hundreds of other failed attempts, including abspath, relpath, and find / replace, and they all lead nowhere. Surely, there is a way to take a full-path filename from a dialog in Windows (in this case, Blender) and split the directory and filename apart?
If you have any ideas how I might work around this problem, please share.
You can try removing the inverted commas form the string while using the variable which has the string stored in it.
I was trying to find file size where file path was chosen by user:
import os
take input on file path
file_path = input("Enter file path without inverted commas:")
prints the size of the file in bytes
print(os.path.getsize(file_path))
Note:
When I copied the path it was copied like this:
"D:\Dev\repo\t1_old\task.py"
So I had to remove the inverted commas, only then the os.path.getsize(file_path) worked.
If I did not remove inverted commas while entering the file path, it gives an error

Removing all special characters from a string that cannot be used inside the command line (python)

I'm making a tk application in which I have to execute a command line application (MP4Box) from python, using subprocess.check_call().
The filename (used in the command) is retrieved from youtube and hence has all types of special characters. I want to remove all characters that can't be used as filenames in the Operating system also btw (i want the implementation would work across multiple platforms)
I tried the solution over here
. windows seems accept the filename but but it returns an error with subproces.check_call().
I tried manually removing the special char from filename and it works good after that. so it isnt a problem with the command.
EDIT:
For eg, i tested for this video. The solution in above link won't remove 'ä' and cause a problem in the command line.
I eventually found the correct answer. Ascii did the trick :)
''.join([t for t in <filenmae> if t.isalnum()]).encode('ascii', 'ignore'))

How to get gdb on Linux to find source file for binary cross compiled on windows

I am trying to debug an application that is cross-compiled on a Windows host for a Linux target.
The problem:
Because the initial compilation is in windows the stored source file paths in the binary is of the form C:\Users\foo\project\.... On the Linux target I have put the source files under \home\foo\project\.... By default gdb does not find the source file because of the different path.
What I have tried so far:
Use "directory" command in gdb to give an exact path for the .c source file in the target Linux system where the app is being debugged. This works but unfortunately there are literally hundreds of files so this solution is unrealistic.
Use the set substitute-path C:\\Users\\foo\\project /home/foo/project command to have gdb substitute all prefixes. Note that the \\ seems necessary such that show substitute-path registers the right string. This unfortunately does not work. My guess is that the substitute-path command does not handle ms-dos style paths.
Tried separating the debug info out into a separate .debug file (see How to generate gcc debug symbol outside the build target?) and then using debugedit to change the paths with the command debugedit --base-dir=C:\Users\foo --dest-dir=/home/foo project.debug. Unfortunately this does not work either. debugedit seems to work fine if the existing path is all UNIX/Linux like but doesn't seem to work with ms-dos style paths.
I have looked around stackoverflow and while there are similar topics I can't find anything that will help me. Would really appreciate any suggestions/help. I realize that cross compiling from Windows is a very roundabout way but can't avoid that for the moment.
Thanks
Although it's rather old question, I did encountered the same problem. I managed to resolve it but using sed on binary executable... (yeah, a 'bit' hack-ish, but did not found another way). With sed I've managed to replace symbols paths right inside the executable, the trick is that new path's length should be the same as the old one.
sed -i "s#C:/srcpath#/srcpath/.#g" ./executable
Be sure to make new path the same length, otherwise the executable will brake.
I also have this same problem. Your option 1 isn't as bad as you think because you can script creating all the 'directory' commands with something like this python code:
def get_directory_paths():
return_array = list()
unix_path = os.path.join('my','unix','path')
for root, dirs, files in os.walk(unix_path):
for dir in dirs:
full_unix_path = os.path.join(root,dir)
escaped_unix_path = re.sub("\s", "\\\\ ", full_unix_path)
return_array.insert(0, "directory " + escaped_unix_path)
return '\n'.join(return_array)
The downside is that if you have two source files with the same name in different directories, I don't think gcc can pick the right one. That worries me, but in my particular situation, I think I'm safe.
For option 2 (which I suspect would fix the aliasing condition from #1), I think the problem is that the substitutions are not ending with a "file separator" according to the linux so they aren't applied:
To avoid unexpected substitution results, a rule is applied only if the from part of the directory name ends at a directory separator. For instance, a rule substituting /usr/source into /mnt/cross will be applied to /usr/source/foo-1.0 but not to /usr/sourceware/foo-2.0. And because the substitution is applied only at the beginning of the directory name, this rule will not be applied to /root/usr/source/baz.c either." (from https://sourceware.org/gdb/current/onlinedocs/gdb/Source-Path.html#index-set-substitute_002dpath )
I haven't tried anything like your #3 and I also considered something like #dragn suggestion, but in my situation the paths are not even close to the same length, so that will be an issue.
I think I'm stuck with #1 and a script, but if anyone has other suggestions, I'm interested options :-)

Android.mk : How to add backslashes automatically

In Android.mk, I read the context of system environment variable like $(MY_ENV_VARIABLE). The env variable contains following string inside "Program(x86) Files".
But the build fails, claiming that the specified library cannot be found. The failure takes place of windows style weird space in "Program(x86) Files".
So my question is, is there any mechanism to automatically escape the special symbols like space (i.e "Program(x86)\ Files", for my case).
You might be able to try using the windows pathing conventions of using the tilde character so instead of C:\Program(x86) Files\mydir it would be C:\PROGRA~2\mydir (PROGRA~1 is for the 64 bit program files).
Like eldar said in the comments it is better to not use spaces in path names because most of make's functions use spaces as delimiters. Another option you could try is to take a look at my suggestion here: WINAVR not finding file in include path with whitespace
Since Android is a pretty complicated build environment it might be hard to see where to place the final substitution unless you know what you're doing and hopefully won't break anything else in the makefile.

Fortran 90 - I/O passing variable as filepath

This seems like it should be an easy fix, but after searching for hours I cannot find a solution.
I want to save a filepath as a character variable, then use the variable in a I/O statement. Below is my code for reading from the file defined by "filepath".
character:: filepath
filepath='c:\users\chris\...\data.txt'
open(unit=1,file=filepath,status='old',action='read',form='formatted',iostat=ierror)
if(ierror.NE.0)then
print*,'file cannot be opened or does not exist'
read*,
endif
......
The program compiles (gfortran compiler using NetBeans IDE), but when I run, I get the error printed to the screen.
Note 1: When I put the filepath directly into the open function as shown below, it seems to work fine
open(unit=1,file='c:\\Users\\Chris\\...\\data.txt',status='old',action='read',form='formatted',iostat=ierror)
Note 2: I have tried all variations of forward/backward, single/double slashes in the filepath variable, so I don't think that is the problem. When I print out "filepath" to the screen as a debugging mechanism (before the open function above), all is get back is "C". So for some reason, it seems I am losing the rest of the filepath. (I will leave my questions regarding what slash method is appropriate until I research it more)
I appreciate any suggestions.
Thanks,
Chris
You've declared filepath to be a character variable of length 1. Change the declaration to something like character(80):: filepath (use a length long enough to contain the entire path).

Resources