我已尝试打开确实存在的文件,但我不断收到以下错误消息:
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")
答案 0 :(得分:0)
您是否尝试过检查是否存在权限问题?
打开终端并cd到正确的目录
:+:
以下是这些权限的含义:
cd -l
尝试跑步:
rwxrwxrwx <-- r refers to read, w to write, and x to execute
--------- <-- a hyphen refers to the permission not existing