gpt4 book ai didi

python - 如何指定 Microsoft Azure Jupyter Notebooks 的路径?

转载 作者:太空宇宙 更新时间:2023-11-03 20:28:51 26 4
gpt4 key购买 nike

我正在尝试将我为 Jupyter Notebook 编写的 Python 脚本上传到 Microsoft Azure Notebooks,但它无法正常工作。

Microsoft Azure 项目有一个文件夹,其中包含我尝试读取的 XLSX 文件和 Python 脚本。当我在 Jupyter Notebook 上运行 Python 脚本时,它不会访问我之前上传到项目的文件夹。

path =r'/Users/chorozco/Documents/Dr.Irwin/6 Column Data Acquisition Converted'
filenames = glob.glob(path + "/*.xlsx")

path = os.getcwd()
files = os.listdir(path)
files

我期待“6 列数据采集转换”中的文件列表,但我得到的是我的 Microsoft Azure 项目中的文件列表:

期望: Script run from Anaconda in my computer

现实: Script run from Microsoft Azure Notebooks

最佳答案

根据您的代码path =r'/Users/chorozco/Documents/Dr.Irwin/6 Column Data Acquisition Converted',我认为您正在MacOS上工作,而不是Linux上。然而,Microsoft Azure Notebooks是基于Linux运行的。因此,Azure Notebook 和本地 Anaconda 之间的代码 os.listdir(path) 的差异是由于不同操作系统上此功能 os.listdir 的 Python 实现不同造成的,例如除 Linux 和 Windows 之外的 MacOS,目录中没有递归列出文件的结果。

这是我的步骤作为引用。

  1. 我在我的 Microsoft Azure Notebooks 帐户中创建了一个名为 Test for Listing xlsx files in a path of Azure Notebook Project 的新项目,并创建了一个新文件夹 6 Column数据采集​​转换如下图。

    图1。

    enter image description here

    图2。

    enter image description here

  2. 我在本地 Windows 上创建了一些 xlsx 文件用于上传,然后移动到我之前在 Azure Notebook 项目中创建的文件夹中进行上传操作,如下图所示。

    图3。

    enter image description here

    图4。

    enter image description here

    图5。

    enter image description here

    图6。

    enter image description here

  3. 我在 Python 3.6 中创建了一个笔记本来运行与您的相同的代码。

    图7。

    enter image description here

    图8。

    enter image description here

  4. 我发现结果与本地 Linux 和 Windows 上的代码相同,但与 MacOS 上的结果不同。

    图 9. 在 Azure Notebook 的 Python 3.6 中运行几乎相同的代码

    enter image description here

    图 10. 在 Azure Notebook 的 Python 2.7 中运行几乎相同的代码

    enter image description here

    图 11. Windows 上 os.listdir 的结果

    enter image description here

    图 12. Linux 上 os.listdir 的结果

    enter image description here

所以我认为这个问题是由MacPython引起的,请再检查一下。希望对您有所帮助。

关于python - 如何指定 Microsoft Azure Jupyter Notebooks 的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57650452/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com