'Databricks command says databricks-cli isn't configured when run from Python (with os.system()) but works fine when pasted into command line

My Python code constructs a string in the form
myCmd = 'databricks fs cp dbfs:/mnt/extracts/dsp/{}/full.xml "{}"'.format(extractId, file_path)

This results in a string like this: databricks fs cp dbfs://mt/extracts/dsp/123/full.xml "c:\filepath\full.xml"

When I attempt to run this string using os.system(myCmd) I'm given the following warning (either within the Python console, or in the cmd window):
Error: InvalidConfigurationError: You haven't configured the CLI yet! Please configure by entering `C:\Users\xxxx\AppData\Local\Continuum\anaconda3\Scripts\databricks configure

But when i copy and paste the constructed myCmd to the command prompt the databricks copy works fine.

I've tried running databricks configure then re-running the Python code, and that doesn't work.



Solution 1:[1]

Before you can run CLI commands, you must set up authentication. To authenticate to the CLI you use a personal access token. To configure the CLI to use the access token, run databricks configure --token.

For more details, refer "Setup authentication".

Here is an article helps you to "Installing, configuring and using the Azure Databricks CLI".

Hope this helps.

Solution 2:[2]

Same issue for me. It said "You haven't configured the CLI yet!" from within the Python Notebook. I changed the Python version to 3 from 2 and it worked fine. Also changing the Databricks Runtime version to something like 5.5-LTS-ML fixes the issue.

Solution 3:[3]

I also had same error message in different context when dealing with mlflow objects
Later I observed that I was getting this error only when I install mlflow as
!pip install mlflow
instead of
%pip install mlflow

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CHEEKATLAPRADEEP-MSFT
Solution 2 Steven Park
Solution 3 arun