@@ -418,12 +418,64 @@ export class DataScienceInstaller extends BaseInstaller {
418418 const interpreter = interpreterUri as PythonEnvironment ;
419419
420420 // Get a list of known installation channels, pip, conda, etc.
421- const channels : IModuleInstaller [ ] = await this . serviceContainer
421+ let channels : IModuleInstaller [ ] = await this . serviceContainer
422422 . get < IInstallationChannelManager > ( IInstallationChannelManager )
423423 . getInstallationChannels ( interpreter ) ;
424424
425425 // Pick an installerModule based on whether the interpreter is conda or not. Default is pip.
426426 const moduleName = translateProductToModule ( product ) ;
427+ const version = `${ interpreter . version ?. major || '' } .${ interpreter . version ?. minor || '' } .${
428+ interpreter . version ?. patch || ''
429+ } `;
430+
431+ // If this is a non-conda environment & pip isn't installed, we need to install pip.
432+ // The prompt would have been disabled prior to this point, so we can assume that.
433+ if (
434+ flags &&
435+ flags & ModuleInstallFlags . installPipIfRequired &&
436+ interpreter . envType !== EnvironmentType . Conda &&
437+ ! channels . some ( ( channel ) => channel . type === ModuleInstallerType . Pip )
438+ ) {
439+ const installers = this . serviceContainer . getAll < IModuleInstaller > ( IModuleInstaller ) ;
440+ const pipInstaller = installers . find ( ( installer ) => installer . type === ModuleInstallerType . Pip ) ;
441+ if ( pipInstaller ) {
442+ traceInfo ( `Installing pip as its not available to install ${ moduleName } .` ) ;
443+ await pipInstaller
444+ . installModule ( Product . pip , interpreter , cancel )
445+ . catch ( ( ex ) =>
446+ traceError (
447+ `Error in installing the module '${ moduleName } as Pip could not be installed', ${ ex } ` ,
448+ ) ,
449+ ) ;
450+
451+ await this . isInstalled ( Product . pip , interpreter )
452+ . then ( ( isInstalled ) => {
453+ sendTelemetryEvent ( EventName . PYTHON_INSTALL_PACKAGE , undefined , {
454+ installer : pipInstaller . displayName ,
455+ requiredInstaller : ModuleInstallerType . Pip ,
456+ version,
457+ envType : interpreter . envType ,
458+ isInstalled,
459+ productName : ProductNames . get ( Product . pip ) ,
460+ } ) ;
461+ } )
462+ . catch ( noop ) ;
463+
464+ // Refresh the list of channels (pip may be avaialble now).
465+ channels = await this . serviceContainer
466+ . get < IInstallationChannelManager > ( IInstallationChannelManager )
467+ . getInstallationChannels ( interpreter ) ;
468+ } else {
469+ sendTelemetryEvent ( EventName . PYTHON_INSTALL_PACKAGE , undefined , {
470+ installer : 'unavailable' ,
471+ requiredInstaller : ModuleInstallerType . Pip ,
472+ productName : ProductNames . get ( Product . pip ) ,
473+ version,
474+ envType : interpreter . envType ,
475+ } ) ;
476+ traceError ( `Unable to install pip when its required.` ) ;
477+ }
478+ }
427479
428480 const isAvailableThroughConda = ! UnsupportedChannelsForProduct . get ( product ) ?. has ( EnvironmentType . Conda ) ;
429481 let requiredInstaller = ModuleInstallerType . Unknown ;
@@ -449,10 +501,6 @@ export class DataScienceInstaller extends BaseInstaller {
449501 }
450502 const installerModule : IModuleInstaller | undefined = channels . find ( ( v ) => v . type === requiredInstaller ) ;
451503
452- const version = `${ interpreter . version ?. major || '' } .${ interpreter . version ?. minor || '' } .${
453- interpreter . version ?. patch || ''
454- } `;
455-
456504 if ( ! installerModule ) {
457505 this . appShell . showErrorMessage ( Installer . couldNotInstallLibrary ( ) . format ( moduleName ) ) . then ( noop , noop ) ;
458506 sendTelemetryEvent ( EventName . PYTHON_INSTALL_PACKAGE , undefined , {
@@ -471,7 +519,7 @@ export class DataScienceInstaller extends BaseInstaller {
471519
472520 return this . isInstalled ( product , interpreter ) . then ( ( isInstalled ) => {
473521 sendTelemetryEvent ( EventName . PYTHON_INSTALL_PACKAGE , undefined , {
474- installer : installerModule ? .displayName || '' ,
522+ installer : installerModule . displayName || '' ,
475523 requiredInstaller,
476524 version,
477525 envType : interpreter . envType ,
0 commit comments