1use std::env::consts::EXE_SUFFIX;
4use std::io;
5use std::io::{BufWriter, Write};
6use std::path::Path;
7
8use console::Term;
9use fs_err::File;
10use itertools::Itertools;
11use owo_colors::OwoColorize;
12use tracing::{debug, trace};
13
14use crate::{Error, Prompt};
15use uv_fs::{CWD, Simplified, cachedir};
16use uv_platform_tags::Os;
17use uv_pypi_types::Scheme;
18use uv_python::managed::{
19 ManagedPythonInstallation, PythonMinorVersionLink, replace_link_to_executable,
20};
21use uv_python::{Interpreter, VirtualEnvironment};
22use uv_shell::escape_posix_for_single_quotes;
23use uv_version::version;
24
25const ACTIVATE_TEMPLATES: &[(&str, &str)] = &[
27 ("activate", include_str!("activator/activate")),
28 ("activate.csh", include_str!("activator/activate.csh")),
29 ("activate.fish", include_str!("activator/activate.fish")),
30 ("activate.nu", include_str!("activator/activate.nu")),
31 ("activate.ps1", include_str!("activator/activate.ps1")),
32 ("activate.bat", include_str!("activator/activate.bat")),
33 ("deactivate.bat", include_str!("activator/deactivate.bat")),
34 ("pydoc.bat", include_str!("activator/pydoc.bat")),
35 (
36 "activate_this.py",
37 include_str!("activator/activate_this.py"),
38 ),
39];
40const VIRTUALENV_PATCH: &str = include_str!("_virtualenv.py");
41
42fn write_cfg(f: &mut impl Write, data: &[(String, String)]) -> io::Result<()> {
44 for (key, value) in data {
45 writeln!(f, "{key} = {value}")?;
46 }
47 Ok(())
48}
49
50#[expect(clippy::fn_params_excessive_bools)]
52pub(crate) fn create(
53 location: &Path,
54 interpreter: &Interpreter,
55 prompt: Prompt,
56 system_site_packages: bool,
57 on_existing: OnExisting,
58 relocatable: bool,
59 seed: bool,
60 upgradeable: bool,
61) -> Result<VirtualEnvironment, Error> {
62 let base_python = if cfg!(unix) && interpreter.is_standalone() {
68 interpreter.find_base_python()?
69 } else {
70 interpreter.to_base_python()?
71 };
72
73 debug!(
74 "Using base executable for virtual environment: {}",
75 base_python.display()
76 );
77
78 let prompt = match prompt {
82 Prompt::CurrentDirectoryName => CWD
83 .file_name()
84 .map(|name| name.to_string_lossy().to_string()),
85 Prompt::Static(value) => Some(value),
86 Prompt::None => None,
87 };
88 let absolute = std::path::absolute(location)?;
89
90 match location.metadata() {
92 Ok(metadata) if metadata.is_file() => {
93 return Err(Error::Io(io::Error::new(
94 io::ErrorKind::AlreadyExists,
95 format!("File exists at `{}`", location.user_display()),
96 )));
97 }
98 Ok(metadata)
99 if metadata.is_dir()
100 && location
101 .read_dir()
102 .is_ok_and(|mut dir| dir.next().is_none()) =>
103 {
104 trace!(
106 "Using empty directory at `{}` for virtual environment",
107 location.user_display()
108 );
109 }
110 Ok(metadata) if metadata.is_dir() => {
111 let is_virtualenv = uv_fs::is_virtualenv_base(location);
112 let name = if is_virtualenv {
113 "virtual environment"
114 } else {
115 "directory"
116 };
117 let hint = format!(
118 "Use the `{}` flag or set `{}` to replace the existing {name}",
119 "--clear".green(),
120 "UV_VENV_CLEAR=1".green()
121 );
122 let err = Err(Error::Io(io::Error::new(
125 io::ErrorKind::AlreadyExists,
126 format!(
127 "A {name} already exists at: {}\n\n{}{} {hint}",
128 location.user_display(),
129 "hint".bold().cyan(),
130 ":".bold(),
131 ),
132 )));
133 match on_existing {
134 OnExisting::Allow => {
135 debug!("Allowing existing {name} due to `--allow-existing`");
136 }
137 OnExisting::Remove(reason) => {
138 debug!("Removing existing {name} ({reason})");
139 let location = location
143 .canonicalize()
144 .unwrap_or_else(|_| location.to_path_buf());
145 uv_fs::remove_virtualenv(&location)?;
146 fs_err::create_dir_all(&location)?;
147 }
148 OnExisting::Fail => return err,
149 OnExisting::Prompt if !is_virtualenv => return err,
151 OnExisting::Prompt => {
152 match confirm_clear(location, name)? {
153 Some(true) => {
154 debug!("Removing existing {name} due to confirmation");
155 let location = location
159 .canonicalize()
160 .unwrap_or_else(|_| location.to_path_buf());
161 uv_fs::remove_virtualenv(&location)?;
162 fs_err::create_dir_all(&location)?;
163 }
164 Some(false) => return err,
165 None => {
167 return Err(Error::Exists {
168 name,
169 path: location.to_path_buf(),
170 });
171 }
172 }
173 }
174 }
175 }
176 Ok(_) => {
177 return Err(Error::Io(io::Error::new(
179 io::ErrorKind::AlreadyExists,
180 format!("Object already exists at `{}`", location.user_display()),
181 )));
182 }
183 Err(err) if err.kind() == io::ErrorKind::NotFound => {
184 fs_err::create_dir_all(location)?;
185 }
186 Err(err) => return Err(Error::Io(err)),
187 }
188
189 let location = absolute;
191
192 let bin_name = if cfg!(unix) {
193 "bin"
194 } else if cfg!(windows) {
195 "Scripts"
196 } else {
197 unimplemented!("Only Windows and Unix are supported")
198 };
199 let scripts = location.join(&interpreter.virtualenv().scripts);
200
201 cachedir::ensure_tag(&location)?;
203
204 fs_err::write(location.join(".gitignore"), "*")?;
206
207 let mut using_minor_version_link = false;
208 let executable_target = if upgradeable {
209 if let Some(minor_version_link) =
210 ManagedPythonInstallation::try_from_interpreter(interpreter)
211 .and_then(|installation| PythonMinorVersionLink::from_installation(&installation))
212 {
213 if !minor_version_link.exists() {
214 base_python.clone()
215 } else {
216 let debug_symlink_term = if cfg!(windows) {
217 "junction"
218 } else {
219 "symlink directory"
220 };
221 debug!(
222 "Using {} {} instead of base Python path: {}",
223 debug_symlink_term,
224 &minor_version_link.symlink_directory.display(),
225 &base_python.display()
226 );
227 using_minor_version_link = true;
228 minor_version_link.symlink_executable.clone()
229 }
230 } else {
231 base_python.clone()
232 }
233 } else {
234 base_python.clone()
235 };
236
237 let python_home = executable_target
242 .parent()
243 .ok_or_else(|| {
244 io::Error::new(
245 io::ErrorKind::NotFound,
246 "The Python interpreter needs to have a parent directory",
247 )
248 })?
249 .to_path_buf();
250 let python_home = python_home.as_path();
251
252 fs_err::create_dir_all(&scripts)?;
254 let executable = scripts.join(format!("python{EXE_SUFFIX}"));
255
256 #[cfg(unix)]
257 {
258 uv_fs::replace_symlink(&executable_target, &executable)?;
259 uv_fs::replace_symlink(
260 "python",
261 scripts.join(format!("python{}", interpreter.python_major())),
262 )?;
263 uv_fs::replace_symlink(
264 "python",
265 scripts.join(format!(
266 "python{}.{}",
267 interpreter.python_major(),
268 interpreter.python_minor(),
269 )),
270 )?;
271 if interpreter.gil_disabled() {
272 uv_fs::replace_symlink(
273 "python",
274 scripts.join(format!(
275 "python{}.{}t",
276 interpreter.python_major(),
277 interpreter.python_minor(),
278 )),
279 )?;
280 }
281
282 if interpreter.markers().implementation_name() == "pypy" {
283 uv_fs::replace_symlink(
284 "python",
285 scripts.join(format!("pypy{}", interpreter.python_major())),
286 )?;
287 uv_fs::replace_symlink("python", scripts.join("pypy"))?;
288 }
289
290 if interpreter.markers().implementation_name() == "graalpy" {
291 uv_fs::replace_symlink("python", scripts.join("graalpy"))?;
292 }
293 }
294
295 if cfg!(windows) {
299 if using_minor_version_link {
300 let target = scripts.join(WindowsExecutable::Python.exe(interpreter));
301 replace_link_to_executable(target.as_path(), &executable_target)
302 .map_err(Error::Python)?;
303 let targetw = scripts.join(WindowsExecutable::Pythonw.exe(interpreter));
304 replace_link_to_executable(targetw.as_path(), &executable_target)
305 .map_err(Error::Python)?;
306 if interpreter.gil_disabled() {
307 let targett = scripts.join(WindowsExecutable::PythonMajorMinort.exe(interpreter));
308 replace_link_to_executable(targett.as_path(), &executable_target)
309 .map_err(Error::Python)?;
310 let targetwt = scripts.join(WindowsExecutable::PythonwMajorMinort.exe(interpreter));
311 replace_link_to_executable(targetwt.as_path(), &executable_target)
312 .map_err(Error::Python)?;
313 }
314 } else if matches!(interpreter.platform().os(), Os::Pyodide { .. }) {
315 let target = scripts.join(WindowsExecutable::Python.exe(interpreter));
318 replace_link_to_executable(target.as_path(), &executable_target)
319 .map_err(Error::Python)?;
320 } else {
321 copy_launcher_windows(
323 WindowsExecutable::Python,
324 interpreter,
325 &base_python,
326 &scripts,
327 python_home,
328 )?;
329
330 match interpreter.implementation_name() {
331 "graalpy" => {
332 copy_launcher_windows(
334 WindowsExecutable::GraalPy,
335 interpreter,
336 &base_python,
337 &scripts,
338 python_home,
339 )?;
340 copy_launcher_windows(
341 WindowsExecutable::PythonMajor,
342 interpreter,
343 &base_python,
344 &scripts,
345 python_home,
346 )?;
347 }
348 "pypy" => {
349 copy_launcher_windows(
351 WindowsExecutable::PythonMajor,
352 interpreter,
353 &base_python,
354 &scripts,
355 python_home,
356 )?;
357 copy_launcher_windows(
358 WindowsExecutable::PythonMajorMinor,
359 interpreter,
360 &base_python,
361 &scripts,
362 python_home,
363 )?;
364 copy_launcher_windows(
365 WindowsExecutable::Pythonw,
366 interpreter,
367 &base_python,
368 &scripts,
369 python_home,
370 )?;
371 copy_launcher_windows(
372 WindowsExecutable::PyPy,
373 interpreter,
374 &base_python,
375 &scripts,
376 python_home,
377 )?;
378 copy_launcher_windows(
379 WindowsExecutable::PyPyMajor,
380 interpreter,
381 &base_python,
382 &scripts,
383 python_home,
384 )?;
385 copy_launcher_windows(
386 WindowsExecutable::PyPyMajorMinor,
387 interpreter,
388 &base_python,
389 &scripts,
390 python_home,
391 )?;
392 copy_launcher_windows(
393 WindowsExecutable::PyPyw,
394 interpreter,
395 &base_python,
396 &scripts,
397 python_home,
398 )?;
399 copy_launcher_windows(
400 WindowsExecutable::PyPyMajorMinorw,
401 interpreter,
402 &base_python,
403 &scripts,
404 python_home,
405 )?;
406 }
407 _ => {
408 copy_launcher_windows(
410 WindowsExecutable::Pythonw,
411 interpreter,
412 &base_python,
413 &scripts,
414 python_home,
415 )?;
416
417 if interpreter.gil_disabled() {
419 copy_launcher_windows(
420 WindowsExecutable::PythonMajorMinort,
421 interpreter,
422 &base_python,
423 &scripts,
424 python_home,
425 )?;
426 copy_launcher_windows(
427 WindowsExecutable::PythonwMajorMinort,
428 interpreter,
429 &base_python,
430 &scripts,
431 python_home,
432 )?;
433 }
434 }
435 }
436 }
437 }
438
439 #[cfg(not(any(unix, windows)))]
440 {
441 compile_error!("Only Windows and Unix are supported")
442 }
443
444 for (name, template) in ACTIVATE_TEMPLATES {
446 if relocatable && *name == "activate.csh" {
450 continue;
451 }
452
453 let path_sep = if cfg!(windows) { ";" } else { ":" };
454
455 let relative_site_packages = [
456 interpreter.virtualenv().purelib.as_path(),
457 interpreter.virtualenv().platlib.as_path(),
458 ]
459 .iter()
460 .dedup()
461 .map(|path| {
462 pathdiff::diff_paths(path, &interpreter.virtualenv().scripts)
463 .expect("Failed to calculate relative path to site-packages")
464 })
465 .map(|path| path.simplified().to_str().unwrap().replace('\\', "\\\\"))
466 .join(path_sep);
467
468 let virtual_env_dir = match (relocatable, name.to_owned()) {
469 (true, "activate") => {
470 r#"'"$(dirname -- "$(dirname -- "$(realpath -- "$SCRIPT_PATH")")")"'"#.to_string()
471 }
472 (true, "activate.bat") => r"%~dp0..".to_string(),
473 (true, "activate.fish") => {
474 r#"'"$(dirname -- "$(cd "$(dirname -- "$(status -f)")"; and pwd)")"'"#.to_string()
475 }
476 (true, "activate.nu") => r"(path self | path dirname | path dirname)".to_string(),
477 (false, "activate.nu") => {
478 format!(
479 "'{}'",
480 escape_posix_for_single_quotes(location.simplified().to_str().unwrap())
481 )
482 }
483 _ => escape_posix_for_single_quotes(location.simplified().to_str().unwrap()),
485 };
486
487 let activator = template
488 .replace("{{ VIRTUAL_ENV_DIR }}", &virtual_env_dir)
489 .replace("{{ BIN_NAME }}", bin_name)
490 .replace(
491 "{{ VIRTUAL_PROMPT }}",
492 prompt.as_deref().unwrap_or_default(),
493 )
494 .replace("{{ PATH_SEP }}", path_sep)
495 .replace("{{ RELATIVE_SITE_PACKAGES }}", &relative_site_packages);
496 fs_err::write(scripts.join(name), activator)?;
497 }
498
499 let mut pyvenv_cfg_data: Vec<(String, String)> = vec![
500 (
501 "home".to_string(),
502 python_home.simplified_display().to_string(),
503 ),
504 (
505 "implementation".to_string(),
506 interpreter
507 .markers()
508 .platform_python_implementation()
509 .to_string(),
510 ),
511 ("uv".to_string(), version().to_string()),
512 (
513 "version_info".to_string(),
514 interpreter.markers().python_full_version().string.clone(),
515 ),
516 (
517 "include-system-site-packages".to_string(),
518 if system_site_packages {
519 "true".to_string()
520 } else {
521 "false".to_string()
522 },
523 ),
524 ];
525
526 if relocatable {
527 pyvenv_cfg_data.push(("relocatable".to_string(), "true".to_string()));
528 }
529
530 if seed {
531 pyvenv_cfg_data.push(("seed".to_string(), "true".to_string()));
532 }
533
534 if let Some(prompt) = prompt {
535 pyvenv_cfg_data.push(("prompt".to_string(), prompt));
536 }
537
538 if cfg!(windows) && interpreter.markers().implementation_name() == "graalpy" {
539 pyvenv_cfg_data.push((
540 "venvlauncher_command".to_string(),
541 python_home
542 .join("graalpy.exe")
543 .simplified_display()
544 .to_string(),
545 ));
546 }
547
548 let mut pyvenv_cfg = BufWriter::new(File::create(location.join("pyvenv.cfg"))?);
549 write_cfg(&mut pyvenv_cfg, &pyvenv_cfg_data)?;
550 drop(pyvenv_cfg);
551
552 let site_packages = location.join(&interpreter.virtualenv().purelib);
554 fs_err::create_dir_all(&site_packages)?;
555
556 #[cfg(unix)]
559 if interpreter.pointer_size().is_64()
560 && interpreter.markers().os_name() == "posix"
561 && interpreter.markers().sys_platform() != "darwin"
562 {
563 match fs_err::os::unix::fs::symlink("lib", location.join("lib64")) {
564 Ok(()) => {}
565 Err(err) if err.kind() == io::ErrorKind::AlreadyExists => {}
566 Err(err) => {
567 return Err(err.into());
568 }
569 }
570 }
571
572 fs_err::write(site_packages.join("_virtualenv.py"), VIRTUALENV_PATCH)?;
574 fs_err::write(site_packages.join("_virtualenv.pth"), "import _virtualenv")?;
575
576 Ok(VirtualEnvironment {
577 scheme: Scheme {
578 purelib: location.join(&interpreter.virtualenv().purelib),
579 platlib: location.join(&interpreter.virtualenv().platlib),
580 scripts: location.join(&interpreter.virtualenv().scripts),
581 data: location.join(&interpreter.virtualenv().data),
582 include: location.join(&interpreter.virtualenv().include),
583 },
584 root: location,
585 executable,
586 base_executable: base_python,
587 })
588}
589
590fn confirm_clear(location: &Path, name: &'static str) -> Result<Option<bool>, io::Error> {
594 let term = Term::stderr();
595 if term.is_term() {
596 let prompt = format!(
597 "A {name} already exists at `{}`. Do you want to replace it?",
598 location.user_display(),
599 );
600 let hint = format!(
601 "Use the `{}` flag or set `{}` to skip this prompt",
602 "--clear".green(),
603 "UV_VENV_CLEAR=1".green()
604 );
605 Ok(Some(uv_console::confirm_with_hint(
606 &prompt, &hint, &term, true,
607 )?))
608 } else {
609 Ok(None)
610 }
611}
612
613#[derive(Debug, Copy, Clone, Eq, PartialEq)]
614pub enum RemovalReason {
615 UserRequest,
617 TemporaryEnvironment,
620 ManagedEnvironment,
623}
624
625impl std::fmt::Display for RemovalReason {
626 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
627 match self {
628 Self::UserRequest => f.write_str("requested with `--clear`"),
629 Self::ManagedEnvironment => f.write_str("environment is managed by uv"),
630 Self::TemporaryEnvironment => f.write_str("environment is temporary"),
631 }
632 }
633}
634
635#[derive(Debug, Copy, Clone, Eq, PartialEq, Default)]
636pub enum OnExisting {
637 #[default]
641 Prompt,
642 Fail,
644 Allow,
647 Remove(RemovalReason),
649}
650
651impl OnExisting {
652 pub fn from_args(allow_existing: bool, clear: bool, no_clear: bool) -> Self {
653 if allow_existing {
654 Self::Allow
655 } else if clear {
656 Self::Remove(RemovalReason::UserRequest)
657 } else if no_clear {
658 Self::Fail
659 } else {
660 Self::Prompt
661 }
662 }
663}
664
665#[derive(Debug, Copy, Clone)]
666enum WindowsExecutable {
667 Python,
669 PythonMajor,
671 PythonMajorMinor,
673 PythonMajorMinort,
675 Pythonw,
677 PythonwMajorMinort,
679 PyPy,
681 PyPyMajor,
683 PyPyMajorMinor,
685 PyPyw,
687 PyPyMajorMinorw,
689 GraalPy,
691}
692
693impl WindowsExecutable {
694 fn exe(self, interpreter: &Interpreter) -> String {
696 match self {
697 Self::Python => String::from("python.exe"),
698 Self::PythonMajor => {
699 format!("python{}.exe", interpreter.python_major())
700 }
701 Self::PythonMajorMinor => {
702 format!(
703 "python{}.{}.exe",
704 interpreter.python_major(),
705 interpreter.python_minor()
706 )
707 }
708 Self::PythonMajorMinort => {
709 format!(
710 "python{}.{}t.exe",
711 interpreter.python_major(),
712 interpreter.python_minor()
713 )
714 }
715 Self::Pythonw => String::from("pythonw.exe"),
716 Self::PythonwMajorMinort => {
717 format!(
718 "pythonw{}.{}t.exe",
719 interpreter.python_major(),
720 interpreter.python_minor()
721 )
722 }
723 Self::PyPy => String::from("pypy.exe"),
724 Self::PyPyMajor => {
725 format!("pypy{}.exe", interpreter.python_major())
726 }
727 Self::PyPyMajorMinor => {
728 format!(
729 "pypy{}.{}.exe",
730 interpreter.python_major(),
731 interpreter.python_minor()
732 )
733 }
734 Self::PyPyw => String::from("pypyw.exe"),
735 Self::PyPyMajorMinorw => {
736 format!(
737 "pypy{}.{}w.exe",
738 interpreter.python_major(),
739 interpreter.python_minor()
740 )
741 }
742 Self::GraalPy => String::from("graalpy.exe"),
743 }
744 }
745
746 fn launcher(self, interpreter: &Interpreter) -> &'static str {
748 match self {
749 Self::Python | Self::PythonMajor | Self::PythonMajorMinor
750 if interpreter.gil_disabled() =>
751 {
752 "venvlaunchert.exe"
753 }
754 Self::Python | Self::PythonMajor | Self::PythonMajorMinor => "venvlauncher.exe",
755 Self::Pythonw if interpreter.gil_disabled() => "venvwlaunchert.exe",
756 Self::Pythonw => "venvwlauncher.exe",
757 Self::PythonMajorMinort => "venvlaunchert.exe",
758 Self::PythonwMajorMinort => "venvwlaunchert.exe",
759 Self::PyPy | Self::PyPyMajor | Self::PyPyMajorMinor => "venvlauncher.exe",
762 Self::PyPyw | Self::PyPyMajorMinorw => "venvwlauncher.exe",
763 Self::GraalPy => "venvlauncher.exe",
764 }
765 }
766}
767
768fn copy_launcher_windows(
774 executable: WindowsExecutable,
775 interpreter: &Interpreter,
776 base_python: &Path,
777 scripts: &Path,
778 python_home: &Path,
779) -> Result<(), Error> {
780 let shim = interpreter
782 .stdlib()
783 .join("venv")
784 .join("scripts")
785 .join("nt")
786 .join(executable.exe(interpreter));
787 match fs_err::copy(shim, scripts.join(executable.exe(interpreter))) {
788 Ok(_) => return Ok(()),
789 Err(err) if err.kind() == io::ErrorKind::NotFound => {}
790 Err(err) => {
791 return Err(err.into());
792 }
793 }
794
795 let shim = interpreter
799 .stdlib()
800 .join("venv")
801 .join("scripts")
802 .join("nt")
803 .join(executable.launcher(interpreter));
804 match fs_err::copy(shim, scripts.join(executable.exe(interpreter))) {
805 Ok(_) => return Ok(()),
806 Err(err) if err.kind() == io::ErrorKind::NotFound => {}
807 Err(err) => {
808 return Err(err.into());
809 }
810 }
811
812 let shim = base_python.with_file_name(executable.launcher(interpreter));
815 match fs_err::copy(shim, scripts.join(executable.exe(interpreter))) {
816 Ok(_) => return Ok(()),
817 Err(err) if err.kind() == io::ErrorKind::NotFound => {}
818 Err(err) => {
819 return Err(err.into());
820 }
821 }
822
823 match fs_err::copy(
827 base_python.with_file_name(executable.exe(interpreter)),
828 scripts.join(executable.exe(interpreter)),
829 ) {
830 Ok(_) => {
831 for directory in [
834 python_home,
835 interpreter.sys_base_prefix().join("DLLs").as_path(),
836 ] {
837 let entries = match fs_err::read_dir(directory) {
838 Ok(read_dir) => read_dir,
839 Err(err) if err.kind() == io::ErrorKind::NotFound => {
840 continue;
841 }
842 Err(err) => {
843 return Err(err.into());
844 }
845 };
846 for entry in entries {
847 let entry = entry?;
848 let path = entry.path();
849 if path.extension().is_some_and(|ext| {
850 ext.eq_ignore_ascii_case("dll") || ext.eq_ignore_ascii_case("pyd")
851 }) {
852 if let Some(file_name) = path.file_name() {
853 fs_err::copy(&path, scripts.join(file_name))?;
854 }
855 }
856 }
857 }
858
859 match fs_err::read_dir(python_home) {
861 Ok(entries) => {
862 for entry in entries {
863 let entry = entry?;
864 let path = entry.path();
865 if path
866 .extension()
867 .is_some_and(|ext| ext.eq_ignore_ascii_case("zip"))
868 {
869 if let Some(file_name) = path.file_name() {
870 fs_err::copy(&path, scripts.join(file_name))?;
871 }
872 }
873 }
874 }
875 Err(err) if err.kind() == io::ErrorKind::NotFound => {}
876 Err(err) => {
877 return Err(err.into());
878 }
879 }
880
881 return Ok(());
882 }
883 Err(err) if err.kind() == io::ErrorKind::NotFound => {}
884 Err(err) => {
885 return Err(err.into());
886 }
887 }
888
889 Err(Error::NotFound(base_python.user_display().to_string()))
890}