Setting INPUT_DIR and OUTPUT_DIR to show locally on os.environ

Hi, I am trying to set the INPUT_DIR and OUTPUT_DIR locally

Followed up all steps on: https://docs.losant.com/notebooks/notebook-file/writing-guide/
Reached: "Since we will be running locally, after you receive your data export, save it to your local inputs directory . In my file structure above, I would place data.csv in ~/src/analytics/inputs"

I am running Jupyter Notebook from the anaconda prompt (installed anaconda as recommended)

  1. The exported file was moved to `~/src/analytics/inputs which was created in the .Jupyter directory.
    Please explain were the following recommendation take place:

$ cd ~/src/analytics # go to my project folder

set input and output env vars when running jupyter

$ INPUT_DIR=~/src/analytics/inputs OUTPUT_DIR=~/src/analytics/outputs jupyter notebook

The windows comand prompt or Anaconda command Prompt does not accept:
INPUT_DIR=~/src/analytics/inputs OUTPUT_DIR=~/src/analytics/outputs jupyter notebook

  1. Not sure were to run the below command when running jupyter notebook:
    INPUT_DIR=(pwd) OUTPUT_DIR=(pwd) jupyter-notebook

  2. As a result of the above, I can not seem to set up my os.environ to show the path to: OUTPUT_DIR or INPUT_DIR
    Tried running the Python 3 under jupyter with:
    import os
    print(os.environ[‘INOUT_DIR’])
    print(os.environ[‘OUTOUT_DIR’])

am not getting the directories showing up

  1. Tried the “Debugging Losant Notebooks” notebook from May 7th by anaptfox and got the same result of no directory path on os.environ

Please assist and direct me how to set up the local INPUT/OUTPUT directories as I launch jupyter notbook

Hi @tirosh_gutte,

The instructions of the Writing Guide, are for MacOS and Linux. I’ll update the instructions to reflect that.

But, what you would need to do here, is set the Environment Variables and the file path properly for Windows.

Instead, you could add this to the top of your notebook:

try:
  %env 'INPUT_DIR'
except:
    input_dir = os.getcwd() + '/input'
    %set_env INPUT_DIR $input_dir
    pass

try:
  %env 'OUTPUT_DIR'
except:
    output_dir = os.getcwd() + '/output'
    %set_env OUTPUT_DIR $output_dir
    pass

Then, you can edit the line input_dir = os.getcwd() + '/input' to manually set the path when the environment variable does not exist. So, locally, you can manually set, but once running in Losant the environment variables will work properly.

Thank you very much it passed the os.environ test

image

I have the data.csv file in the following directory:
C:\Users\ussatamgi.jupyter\analytics\input\data.csv
The file table construction is as follows:
image

Got a FileNotFoundError when I tried to read the data table:

image
image

What might be a reason for this error message?

Sweet! Happy that works.

That error means that your notebook could not find the file.

Is data.csv in your input directory?

It looks like your input directory is C:\Users\ussatamgi\.jupyter\analytics\input

Yes, it is in this directory

If you print the output of os.path.join(os.environ['INPUT_DIR'], 'data.csv'), do you get the correct path?

Yes, Thank you for looking into this

@tirosh_gutte,

From what it looks like, your paths are correct. However, if you’re still getting a “File Not Found” error, it means your Local Notebook can’t find the file. There is not much help I can provide on my end to debug this.

From here, I would create a simple notebook to ensure that I can simply read a file. Something like this:

import pandas as pd

input_dir = 'put path here'

dataset = pd.read_csv(input_dir, 'data.csv')

print(dataset)

After some searching online, I think I may have found something:

You should try putting r in front of your file paths when you specify them:

Example:

try:
  %env 'INPUT_DIR'
except:
    input_dir = r"C:\Users\ussatamgi\.jupyter\analytics\input"
    %set_env INPUT_DIR $input_dir
    pass
1 Like

You solved it, Thank you for spending the time on this.