@@ -22,7 +22,8 @@ use uv_installer::{SatisfiesResult, SitePackages};
22
22
use uv_pep508:: PackageName ;
23
23
use uv_pypi_types:: { Conflicts , Requirement } ;
24
24
use uv_python:: {
25
- EnvironmentPreference , Prefix , PythonEnvironment , PythonRequest , PythonVersion , Target ,
25
+ EnvironmentPreference , Prefix , PythonEnvironment , PythonInstallation , PythonPreference ,
26
+ PythonRequest , PythonVersion , Target ,
26
27
} ;
27
28
use uv_requirements:: { RequirementsSource , RequirementsSpecification } ;
28
29
use uv_resolver:: {
@@ -32,8 +33,8 @@ use uv_resolver::{
32
33
use uv_types:: { BuildIsolation , HashStrategy } ;
33
34
34
35
use crate :: commands:: pip:: loggers:: { DefaultInstallLogger , DefaultResolveLogger , InstallLogger } ;
35
- use crate :: commands:: pip:: operations:: report_target_environment;
36
36
use crate :: commands:: pip:: operations:: Modifications ;
37
+ use crate :: commands:: pip:: operations:: { report_interpreter, report_target_environment} ;
37
38
use crate :: commands:: pip:: { operations, resolution_markers, resolution_tags} ;
38
39
use crate :: commands:: { diagnostics, ExitStatus , SharedState } ;
39
40
use crate :: printer:: Printer ;
@@ -76,6 +77,7 @@ pub(crate) async fn pip_install(
76
77
break_system_packages : bool ,
77
78
target : Option < Target > ,
78
79
prefix : Option < Prefix > ,
80
+ python_preference : PythonPreference ,
79
81
concurrency : Concurrency ,
80
82
native_tls : bool ,
81
83
allow_insecure_host : & [ TrustedHost ] ,
@@ -138,22 +140,31 @@ pub(crate) async fn pip_install(
138
140
)
139
141
. collect ( ) ;
140
142
141
- // Determine whether we're modifying the discovered environment, or a separate target.
142
- let mutable = !( target. is_some ( ) || prefix. is_some ( ) ) ;
143
-
144
143
// Detect the current Python interpreter.
145
- let environment = PythonEnvironment :: find (
146
- & python
147
- . as_deref ( )
148
- . map ( PythonRequest :: parse)
149
- . unwrap_or_default ( ) ,
150
- EnvironmentPreference :: from_system_flag ( system, mutable) ,
151
- & cache,
152
- ) ?;
153
-
154
- if mutable {
144
+ let environment = if target. is_some ( ) || prefix. is_some ( ) {
145
+ let installation = PythonInstallation :: find (
146
+ & python
147
+ . as_deref ( )
148
+ . map ( PythonRequest :: parse)
149
+ . unwrap_or_default ( ) ,
150
+ EnvironmentPreference :: from_system_flag ( system, false ) ,
151
+ python_preference,
152
+ & cache,
153
+ ) ?;
154
+ report_interpreter ( & installation, true , printer) ?;
155
+ PythonEnvironment :: from_installation ( installation)
156
+ } else {
157
+ let environment = PythonEnvironment :: find (
158
+ & python
159
+ . as_deref ( )
160
+ . map ( PythonRequest :: parse)
161
+ . unwrap_or_default ( ) ,
162
+ EnvironmentPreference :: from_system_flag ( system, true ) ,
163
+ & cache,
164
+ ) ?;
155
165
report_target_environment ( & environment, & cache, printer) ?;
156
- }
166
+ environment
167
+ } ;
157
168
158
169
// Apply any `--target` or `--prefix` directories.
159
170
let environment = if let Some ( target) = target {
0 commit comments