为了账号安全,请及时绑定邮箱和手机立即绑定

如何解决 FileNotFoundError: [Errno 2] Python 3.7/Mac

如何解决 FileNotFoundError: [Errno 2] Python 3.7/Mac

潇湘沐 2021-12-21 16:29:02
细节:Python 3.7.1,Mac OS High Sierra 10.13.6。我正在使用 IDLE 并通过终端运行程序。我最近在 MNIST 手写数字上取得了成功,现在我正在尝试用我自己的数据集训练一个生成对抗网络。数据集是一个图像文件夹。错误:Traceback (most recent call last):  File "Pride.py", line 29, in <module>    listing = os.listdir(path1)    FileNotFoundError: [Errno 2] No such file or directory: 'Users/darren/Desktop/Pride'我已经查看了有关此问题的其他线程,但不明白我的路径有什么问题,所以如果我的错误是由于一些简单的原因,我深表歉意。我从终端执行的 Python 文件和我的数据集文件夹都在我的桌面上。到目前为止,这是我的代码:from keras.models import Sequentialfrom keras.layers.core import Dense, Dropout, Activation, Flattenfrom keras.layers.convolutional import Convolution2D, MaxPooling2Dfrom keras.optimizers import SGD,RMSprop,adamfrom keras.utils import np_utilsimport numpy as npimport matplotlib.pyplot as pltimport matplotlibimport osimport theanofrom PIL import Imagefrom numpy import *from sklearn.utils import shufflefrom sklearn.model_selection import train_test_split# input image dimensionsimg_rows, img_cols = 200, 200# number of channelsimg_channels = 1#%%#  datapath1 = "Users/darren/Desktop/Pride" #path of folder of images    path2 = "Users/darren/Desktop/Prideresized"  #path of folder to save imageslisting = os.listdir(path1) num_samples=size(listing)print ("num_samples")for file in listing:    im = Image.open(path1 + '\\' + file)       img = im.resize((img_rows,img_cols))    gray = img.convert('L')    gray.save(path2 +'\\' +  file, "JPEG")
查看完整描述

2 回答

?
慕妹3146593

TA贡献1820条经验 获得超9个赞

在 mac os 中,如果您将数据集文件或任何其他文件保存在文档文件夹中,则该文件路径的代码可能如下所示


melbourne_file_path = **'/Users/adi/Documents/Top250.csv'**

melbourne_data = pd.read_csv(melbourne_file_path) 

melbourne_data.describe()


查看完整回答
反对 回复 2021-12-21
?
开满天机

TA贡献1786条经验 获得超13个赞

如果您使用相对路径(不以 a 开头的路径/),您需要更改它们,使它们与脚本的位置相关。


在你的情况下:


path1 = "Pride" #path of folder of images    

path2 = "Prideresized"  #path of folder to save images


查看完整回答
反对 回复 2021-12-21
  • 2 回答
  • 0 关注
  • 479 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号