Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't Find Path
#1
I get the following error {the last line shown} regarding the path. "The system cannot find the path specified: './Data/train' "

The location of the train folder is correct. Do I have the format wrong?

In the main file, main.py:

train_dir = os.path.join(data_dir, 'C:\Documents\Pyro\dogs-vs-cats\train')
train_dataset = datasetloader(train_dir, transform=train_transform)  **error**
In another file, dataset.py:

class datasetloader(Dataset):
    def __init__(self, path, transform=None):
        self.classes   = os.listdir(path)  ##the error causing line  **error**
Larz60+ write Oct-30-2023, 02:53 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Modified for you this time. Please use BBCode tags on future posts.
Reply
#2
train_dir = os.path.join(data_dir, 'C:\Documents\Pyro\dogs-vs-cats\train')

must be wrong, what's the path of data_dir?
Reply
#3
>>> p = 'C:\Documents\Pyro\dogs-vs-cats\train'
>>> print(p)
C:\Documents\Pyro\dogs-vs-cats	rain
Now see the problem,so never single \ in path because of escape characters.
Add r or turn around /.
>>> p = r'C:\Documents\Pyro\dogs-vs-cats\train'
>>> print(p)
C:\Documents\Pyro\dogs-vs-cats\train

>>> p = r'C:/Documents/Pyro/dogs-vs-cats/train'
>>> print(p)
C:/Documents/Pyro/dogs-vs-cats/train
Reply
#4
Yes, I tried the / and still same error.
Reply
#5
(Oct-29-2023, 06:05 PM)hatflyer Wrote: I get the following error {the last line shown} regarding the path. "The system cannot find the path specified: './Data/train' "

The location of the train folder is correct. Do I have the format wrong?

In the main file, main.py:

train_dir = os.path.join(data_dir, 'C:\Documents\Pyro\dogs-vs-cats\train')
train_dataset = datasetloader(train_dir, transform=train_transform) **error**


In another file, dataset.py:

class datasetloader(Dataset):
def __init__(self, path, transform=None):
self.classes = os.listdir(path) ##the error causing line **error**

(Oct-29-2023, 07:47 PM)Axel_Erfurt Wrote: train_dir = os.path.join(data_dir, 'C:\Documents\Pyro\dogs-vs-cats\train')

must be wrong, what's the path of data_dir?

I tried this:

data_dir = 'C:/Documents/Pyro/dogs-vs-cats'
train_dir = os.path.join(data_dir, '/train')
test_dir = os.path.join(data_dir, '/test')

Still fails.
Reply
#6
remove slash

train_dir = os.path.join(data_dir, 'train')
test_dir = os.path.join(data_dir, 'test')
hatflyer likes this post
Reply
#7
Thanks much!
Reply
#8
Some day, hopefully soon, the os module will go away. Use pathlib.
from pathlib import Path

data_dir = Path('C:/Documents/Pyro/dogs-vs-cats')
train_dir = data_dir / 'train'
test_dir = data_dir / 'test'
Reply
#9
(Oct-29-2023, 11:37 PM)deanhystad Wrote: Some day, hopefully soon, the os module will go away.
I'm not in a hurry. When the os module goes away, a part of the soul of Python will go away. The os module has always been there since the 1990s. The os module is a low-level module that contains many interesting things. I don't think it is in conflict with higher level modules such as pathlib or subprocess. It should be used for specialized purposes only.
Axel_Erfurt likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,224 Sep-09-2021, 01:25 PM
Last Post: Yoriz
Exclamation "System cannot find path specified"(Geany) kiwi99 2 3,902 Mar-18-2021, 07:37 PM
Last Post: kiwi99
  [split] FileNotFoundError...System cannot find the path specified powerrocker 1 2,062 Oct-03-2019, 09:09 AM
Last Post: buran
  FileNotFoundError...System cannot find the path specified alex9745 28 21,557 Jul-23-2019, 05:14 AM
Last Post: alex9745
  [python]FileNotFoundError...System cannot find the path specified creichle 1 3,644 Jan-30-2019, 12:49 AM
Last Post: Larz60+
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,780 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020