•   over 1 year ago

hidden file .env cannot be viewed in jupyter

Hey Team,

We have created .env files that store the environment variables once docker is launched but unable to view them as the jupyter config does not allow viewing hidden files. Any way to solve them?

  • 2 comments

  •   •   over 1 year ago

    Yes, Jupyter Notebook, by default, doesn't display hidden files (files starting with a dot, like .env). Here are a few ways to access your .env file:

    Method 1: Enable Hidden Files in JupyterLab
    If you're using JupyterLab:
    Go to Settings: Click the gear icon in the top right corner, then select "Advanced Settings Editor".
    Modify ContentsManager: Find the ContentsManager section under the "Server" tab.
    Enable Hidden Files: Set the allow_hidden option to true.
    Restart JupyterLab: You might need to refresh or restart JupyterLab for the changes to take effect.

    Method 2: Symbolic Link (All Jupyter Versions)
    Create a symbolic link to your .env file without the leading dot:
    Code

    ln -s /path/to/.env /path/to/env
    This creates a non-hidden file named env that points to your .env file. You can then access it in Jupyter Notebook.

    Method 3: Access Environment Variables Directly
    You can directly access the environment variables stored in your .env file using the os module in Python:
    Python

    import os
    from dotenv import load_dotenv

    load_dotenv() # Load environment variables from .env file

    my_variable = os.getenv('MY_VARIABLE')
    print(my_variable)

    Important Security Note:
    Be cautious when storing sensitive information in .env files. Make sure your .env file is not tracked by version control systems like Git.
    Consider using a secrets management solution for more robust security.

  •   •   over 1 year ago

    Thanks for the response. We are now looking to use the secrets.

Comments are closed.