IOError:[Errno 2] Mac上没有这样的文件或目录

时间:2015-11-08 01:11:09

标签: python excel operating-system xlrd

我已尝试打开确实存在的文件,但我不断收到以下错误消息:

No such file or directory on Mac

我已确定它与python代码位于同一目录中。我还尝试更改Excel文档的名称以及文档是.xls还是.xlsx,但它没有用。

以下是我尝试过的几个版本,但到目前为止,它们都给了我相同的结果。

import os.path
book = open(os.path.expanduser("~/Desktop/Crimes.xlsx"))

import xlrd
import os.path
book = xlrd.open_workbook(os.path.join("/Users/caitlinwesterfield",'Crime.xls')

import xlrd
book = xlrd.open_workbook('Crime.xls')

import xlrd
book = open('/Users/caitlinwesterfield/Desktop/Crime.xls', "r")

import xlrd
book = open("~/Crime.xls", "r")

import xlrd
book = open(os.path.expanduser(r"~/Desktop/Crime.xls"))

import xlrd
book = open('Crime.xls')

import xlrd
book = open(os.path.expanduser("/Users/caitlinwesterfield/Desktop/Crime.xls"))

import xlrd
import os
book = xlrd.open_workbook(os.path.join("/Users/caitlinwesterfield","TypesOfCrime.xls"))

import xlrd
book = xlrd.open_workbook("typesofcrime.xls")

1 个答案:

答案 0 :(得分:0)

您是否尝试过检查是否存在权限问题?

打开终端并cd到正确的目录

:+:

以下是这些权限的含义:

cd -l

enter image description here

尝试跑步:

rwxrwxrwx  <-- r refers to read, w to write, and x to execute
---------  <-- a hyphen refers to the permission not existing 

image source and more info

how to use the terminal