Search code examples
powershelldatabricksdatabricks-cli

databricks-cli installed, modules not visible


I installed the Databricks CLI, but I am unable to work with the library as such:

In powershell, I have set the working directory to: C:\Users\DNaught1\AppData\Local\Programs\Python\Python39\Scripts

I know the module is there:

Mode LastWriteTime Length Name

-a---- 13/10/2020 1:46 PM 74752 databricks.exe**

I then try to see the version but no luck as shown below:

PS C:\Users\DNaught1\AppData\Local\Programs\Python\Python39\Scripts> databricks --version

databricks : The term 'databricks' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

  • databricks --version
  •   + CategoryInfo          : ObjectNotFound: (databricks:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    
    
    

Suggestion [3,General]: The command databricks was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\databricks". See "get-help about_Command_Precedence" for more details.


Solution

  • I managed to work around it by using the following:

    1- In Python use the command below to install the CLI module

    package_names=['databricks-cli', 'requests'] #packages to install
    pip.main(['install'] + package_names + ['--upgrade'])
    

    2- In powershell cli: change the context to the working directory:

    Set-Location -Path C:\Users\DNaught1\AppData\Local\Programs\Python\Python39\Scripts
    

    3 - Configure the databricks cli:

    .\databricks.exe configure--token
    .\databricks configure --token
    Host: https://xxx.azuredatabricks.net
    Token: dapi2b2dxxxxxxxxxa02c9e6866d322 - Access token for Secrets
    

    4 - Write-host Configuration file for databricks access

    Set-Content .databrickscfg "[DEFAULT]"
    >> Add-Content .databrickscfg "host = https://xxx.azuredatabricks.net"
    >> Add-Content .databrickscfg "token = dapi2b2dxxxxxxxxxa02c9e6866d322"
    

    5 - Validate by checking file storage

    .\dbfs ls