FileNotFoundError with absolute path when trying to read tarball

python read tar.gz file without extracting
python read tar file without extracting
python open tgz file
pandas tar file
python tarfile extract to memory
python tarfile stream
python create tar file from directory
python create tar file in memory

I am trying to read from a tar-file but despite specifying the absolute path i get a FileNotFoundError.

This is the relevant portion of code:

1 from pathlib import Path
3 testPath = Path("G:/test.tar")
4 tar =, "r")
5 ...

and the file definitely exists.

But what I get is (originating from line 4):

FileNotFoundError: [Errno 2] No such file or directory: 'G:\\test.tar'

(I am using PyCharm btw.) What am I missing? I will gladly provide additional information if needed.

Check to make sure your script/file is located in the correct directory

from pathlib import Path
import tarfile

testPath = Path("Songs.txt.tar")
tar =, "r")
print(tar) # Returns <tarfile.TarFile object at 0x100d44f98>

print(tarfile.is_tarfile("Songs.txt.tar")) # Returns True if its tar file

tarfile – Tar archive access, The tarfile module provides read and write access to UNIX tar True bad_example.tar False notthere.tar [Errno 2] No such file or directory: 'notthere.tar​' 'notthere.txt' ]: try: info = t.getmember(filename) except KeyError: print  Objective: Extract a tar file with absolute path to a relative or different path. For example, if a tar arahive contains the file /etc/hosts, it has to be extracted to /home/user/etc/hosts instead. Let’s say that you have the following tar archive that stores a file – /etc/hosts.

Since in the line number 3 you are generating file path using the following line:

testPath = Path("G:/test.tar")

testPath variable is of type pathlib.WindowsPath. while in the next requires filepath in string format.

Please try following:

testPath = Path("G:/test.tar")
tar =, "r")


testPath = str(Path("G:/test.tar"))
tar =, "r")

tarfile.TarError Python Example, def untar(archive): tar = None try: tar = for member in of a file :param str: Absolute path to the downloaded content :param str cache_dir: path to save try: f = tar.extractfile(member) pyDict['content'] =​  Bear in mind that the path you provide for "source" is relative to the "-C". Like, that's what @thinice wrote, it's just that if you still provide an absolute path instead of relative even when using "-C", you don't get the desired result. – GuyPaddock Dec 7 '16 at 21:52


after a recent pc-reset I forgot to change explorer-view to "always show file-type-extension" again which led to me not recognizing that it should have been


as there were only other folders in this directory apart from the file in question. So adjusting my testPath solved that.

cpython/ at master · python/cpython · GitHub, gzipname = os.path.join(TEMPDIR, "testtar.tar.gz"). bz2name "seek() to absolute position failed") "read() at file's end did not return empty string"). try: with open('/path/to/file', 'r') as fh: # Load configuration file values except FileNotFoundError: # Keep preset values In this example, we try to open the file using a with statement. If successful, we can load our configuration file values.

FileNotFoundError when extracting tarball · Issue #6707 · conda , error: FileNotFoundError(2, 'No such file or directory') command: File "C:\Users\​Anurag\Anaconda3\lib\site-packages\conda\gateways\disk\", Getting the same thing this morning when trying to install conda install -c  If tarfilename has no extension, MATLAB ® appends the .tar extension. If you specify a .tgz or .gz extension, tar compresses the specified files using gzip. tarfilename must include a path relative to the current folder or an absolute path.

Finding Your Files in Kaggle Kernels, If you don't have any data files listed, click on the button to add a data file. To get the That causes the file's path to show up in the main window. It will look When i try clicking on a file with model weights, that is all it says. FileNotFoundError: [Errno 2] No such file or directory: '. 0. how to read txt file in kaggle notebook. Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

Accessing data in the Kaggle script, kaggle\Titanic') # Set working directory titanictrain = pd.readcsv("train.csv") #read data from csv file. I get the error: FileNotFoundError: [Errno 2] No such file or  Stack Overflow Public questions and answers; Teams Private questions and answers for your team; Enterprise Private self-hosted questions and answers for your enterprise; Jobs Programming and related technical career opportunities

  • There's nothing wrong with this code. Are you sure the file is there and readable by the user the Python is running as?
  • It is most definitely there (recognized by explorer and PowerShell as well with non-zero filesize) and I am executing PyCharm as admin.
  • Ooohhhh you directed me in the right direction so i could resolve the issue. Windows was cutting of the fact that this is gzipped, which means it is actually test.tar.gz. Which I didn't see due to the fact that there are only folders apart form this file in this particular directory. I just recognized it taking a second look at the powershell. Thanks for the hint! (I feel slightly stupid now.)
  • There's no need for str() here. You can pass a Path to open() just fine.
  • but doing so the error is reported in the execution, if you covert it to str it is working fine. What could be the reason for failure without converting it to str?