Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with reading a path
#1
i'm having a problem on reading a path that contains a group of images, i have the paths on my desktop but i can't read them

Can you guys help me?

I have the exact code on a computers friend and it runs perfeclty

where is the code

from sklearn.decomposition import NMF from matplotlib import pyplot as plt import cv2 import numpy as np import os import sys import statistics ## upload imgs e returns names e imgs def uploadImg(dir1,dir2): cityscape_original = [] landscape_original = [] nameList = [[] for _ in range(512)] imgList = [[] for _ in range(512)] for file in os.listdir('./Desktop/landscape'): if file.endswith(".jpg"): nameList[0].append(file) orig = cv2.imread('./Desktop/landscape' + file) orig = cv2.cvtColor(orig, cv2.COLOR_BGR2RGB) cityscape = cv2.resize(orig,(512,512)) #cityscape_original.append(cityscape) imgList[0].append(cityscape) for file in os.listdir('./Desktop/cityscape'): if file.endswith(".jpg"): nameList[1].append(file) orig = cv2.imread('./sktop/cityscape' + file) orig = cv2.cvtColor(orig, cv2.COLOR_BGR2RGB) landscape = cv2.resize(orig,(512,512)) #landscape_original.append(landscape) imgList[1].append(landscape) return nameList,imgList dir1 = os.listdir('./Desktop/cityscape') dir2 = os.listdir('./Desktop/landscape') name,img = uploadImg(dir1, dir2)
And this is my error

Error:
FileNotFoundError Traceback (most recent call last) <ipython-input-8-d8d91223d726> in <module> ----> 1 dir1 = os.listdir('./Desktop/cityscape') 2 dir2 = os.listdir('./Desktop/landscape') 3 name,img = uploadImg(dir1, dir2) FileNotFoundError: [WinError 3] The system cannot find the path specified: './Desktop/cityscape'
thanks for the support
Reply
#2
Have you tried those paths without the initial './'?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
yes, i've tried without the initial './' and i've got the same error
Reply
#4
What's the absolute path of where you're running the python file? That could be different than wherever the file is saved, especially if you're running it from an ide.

Is the path you're running it from your Desktop's parent folder (which I think is just your user folder)?
Reply
#5
(Jan-04-2019, 03:59 PM)nilamo Wrote: What's the absolute path of where you're running the python file? That could be different than wherever the file is saved, especially if you're running it from an ide.

Is the path you're running it from your Desktop's parent folder (which I think is just your user folder)?

Where do i find the absolute path?

Sorry for the question but i'm really new with python and this kind of stuff is hard to me xD

ps: I'm using Jupiter as Ide
Reply
#6
(Jan-04-2019, 04:08 PM)gkiller007 Wrote: Where do i find the absolute path?

import os import sys try: root = os.path.dirname(os.path.abspath(__file__)) except NameError: import sys root = os.path.dirname(os.path.abspath(sys.argv[0])) print (root)
Reply
#7
(Jan-04-2019, 04:28 PM)Axel_Erfurt Wrote:
(Jan-04-2019, 04:08 PM)gkiller007 Wrote: Where do i find the absolute path?
 import os import sys try: root = os.path.dirname(os.path.abspath(__file__)) except NameError: import sys root = os.path.dirname(os.path.abspath(sys.argv[0])) print (root) 

I've done it and the result was this:

C:\Users\gonca\Anaconda3\lib\site-packages


What do i do with this?
Reply
#8
Do you saved your file in C:\Users\gonca\Anaconda3\lib\site-packages ?

If so, that's not a good idea.
Reply
#9
(Jan-04-2019, 04:41 PM)Axel_Erfurt Wrote: Do you saved your file in C:\Users\gonca\Anaconda3\lib\site-packages ? If so, that's not a good idea.

No, it is saved at desktop, the project itself and the paths that i'm trying to read

The result is the same

C:\Users\gonca\Anaconda3\lib\site-packages
Reply
#10
So the files you're trying to open are in C:\Users\gonca\Anaconda3\lib\site-packages\Desktop\cityscape and C:\Users\gonca\Anaconda3\lib\site-packages\Desktop\landscape, correct?

If not, then I'd suggest either using os.chdir() to change where you think you are to match where your file actually is, or using absolute paths to reference your files/folders.

Here's an example of using os.chdir():
import os import pathlib current_file = pathlib.Path(__file__) current_location = current_file.parent.absolute() os.chdir(current_location) # references from here on out to relative paths will be relative to wherever this file exists print(os.getcwd())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Excel file reading problem max70990 1 2,288 Dec-11-2022, 07:00 PM
Last Post: deanhystad
  Loop reading csv file problem faustineaiden 1 2,645 Dec-11-2021, 08:40 AM
Last Post: ibreeden
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 4,061 Sep-09-2021, 01:25 PM
Last Post: Yoriz
Exclamation Path sacn problem lucky511 10 6,638 Jun-24-2021, 12:09 PM
Last Post: Axel_Erfurt
  Subprocess.Popen() not working when reading file path from csv file herwin 13 30,558 May-07-2021, 03:26 PM
Last Post: herwin
  Strange Problem when reading from excel faryad13 3 3,885 Nov-04-2020, 03:48 PM
Last Post: DeaD_EyE
  problem about maze path finder Simurg 2 3,223 Aug-16-2020, 01:10 PM
Last Post: Simurg
  Reading integers from a file; the problem may be the newline characters JRWoodwardMSW 2 3,620 Jul-14-2020, 02:27 AM
Last Post: bowlofred
  Problem reading data from file player1681 2 5,720 May-22-2020, 08:57 AM
Last Post: player1681
  Problem with reading and writing to file. darktitan 2 3,474 Jul-20-2019, 06:06 PM
Last Post: darktitan

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.