简体   繁体   English

如何为 Microsoft Azure Jupyter Notebooks 指定路径?

[英]How to specify a path for Microsoft Azure Jupyter Notebooks?

I am trying to upload a Python script I wrote for Jupyter Notebook to Microsoft Azure Notebooks, but it is not working correctly.我正在尝试将我为 Jupyter Notebook 编写的 Python 脚本上传到 Microsoft Azure Notebooks,但它无法正常工作。

The Microsoft Azure project has a folder with XLSX files that I am trying to read, and the Python script. Microsoft Azure 项目有一个文件夹,其中包含我正在尝试读取的 XLSX 文件和 Python 脚本。 When I run the Python script on Jupyter Notebook it doesn't access the folder I previously uploaded to the project.当我在 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

I am expecting the list of the files inside "6 Column Data Acquisition Converted", but instead I get a list of the files inside my Microsoft Azure Project:我期待“6列数据采集转换”中的文件列表,但我得到了我的 Microsoft Azure 项目中的文件列表:

Expectation: Script run from Anaconda in my computer期望:脚本在我的电脑中从 Anaconda 运行

Reality: Script run from Microsoft Azure Notebooks现实:从 Microsoft Azure Notebooks 运行的脚本

Just according to your code path =r'/Users/chorozco/Documents/Dr.Irwin/6 Column Data Acquisition Converted' , I think you are working on MacOS, not Linux. 仅根据您的代码path =r'/Users/chorozco/Documents/Dr.Irwin/6 Column Data Acquisition Converted' ,我认为您使用的是MacOS,而不是Linux。 However, Microsoft Azure Notebooks is based on Linux for running. 但是,Microsoft Azure笔记本基于Linux来运行。 So the difference of code os.listdir(path) between Azure Notebook and your local Anaconda is caused by the different implementation of Python for this feature os.listdir on different OS like MacOS other than Linux and Windows, the result without the files recursively listed in the directories. 因此,Azure Notebook和您的本地Anaconda之间的代码os.listdir(path)差异是由于在不同于Linux和Windows的其他OS(例如MacOS)上,针对此功能os.listdir的Python实现不同而导致的,结果是没有递归列出文件在目录中。

Here is my steps as reference. 这是我的步骤作为参考。

  1. I created a new project named Test for listing xlsx files in a path of Azure Notebook Project in my account of Microsoft Azure Notebooks, and to create a new folder 6 Column Data Acquisition Converted as the figures below. 我创建了一个名为Test for listing xlsx files in a path of Azure Notebook Project的新项目, Test for listing xlsx files in a path of Azure Notebook Project在我的Microsoft Azure Notebooks帐户中Test for listing xlsx files in a path of Azure Notebook Project ,并创建一个新文件夹6 Column Data Acquisition Converted ,如下图。

    Fig 1. 图。1。

    在此处输入图片说明

    Fig 2. 图2。

    在此处输入图片说明

  2. I created some xlsx files on my local Windows for uploading, then move to the folder I created in Azure Notebook project previously to do the upload operation as the figures below. 我在本地Windows上创建了一些xlsx文件以进行上载,然后移至之前在Azure Notebook项目中创建的文件夹,以进行上图所示的上载操作。

    Fig 3. 图3。

    在此处输入图片说明

    Fig 4. 图4。

    在此处输入图片说明

    Fig 5. 图5。

    在此处输入图片说明

    Fig 6. 图6。

    在此处输入图片说明

  3. I created a notebook in Python 3.6 to run the same code with yours. 我在Python 3.6中创建了一个笔记本,以与您的笔记本运行相同的代码。

    Fig 7. 图7。

    在此处输入图片说明

    Fig 8. 图8。

    在此处输入图片说明

  4. I found the result is as same as the code on my local Linux and Windows, but other than your result on MacOS. 我发现结果与本地Linux和Windows上的代码相同,但与MacOS上的结果不同。

    Fig 9. The almost same code run in Python 3.6 of Azure Notebook 图9.几乎相同的代码在Azure Notebook的Python 3.6中运行

    在此处输入图片说明

    Fig 10. The almost same code run in Python 2.7 of Azure Notebook 图10.几乎相同的代码在Azure Notebook的Python 2.7中运行

    在此处输入图片说明

    Fig 11. The result of os.listdir on Windows 图11. Windows上的os.listdir的结果

    在此处输入图片说明

    Fig 12. The result of os.listdir on Linux 图12. Linux上的os.listdir的结果

    在此处输入图片说明

So I think the issue was caused by MacPython, please check it again. 因此,我认为该问题是由MacPython引起的,请再次检查。 Hope it helps. 希望能帮助到你。

Wow, thank you so much Peter for your explanation. 哇,非常感谢Peter的解释。 It was very helpful. 这非常有帮助。 I just started coding on Python and I didn't even know there was a difference when trying implement Python on Mac. 我刚刚开始使用Python进行编码,我什至不知道尝试在Mac上实现Python会有什么区别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM