question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Options to improve Python runtime autodiscovery on Windows

See original GitHub issue

Pipenv currently has two Python runtime discovery and/or installation strategies:

  1. Search PATH (in pipenv.cli.find_a_system_python), adding any pyenv environments to the end before it does so
  2. Install it with pyenv (in pipenv.cli.ensure_python)

This misses a few potential possibilities for improvement on Windows:

  1. Discovery based on the Windows launcher configuration file (https://docs.python.org/3/using/windows.html#customization)
  2. Discovery based on the Windows registry (https://github.com/zooba/pep514tools#usage)
  3. Supporting conda based automatic Python installation in addition to pyenv installation
  4. Supporting @uranusjr’s https://github.com/uranusjr/pythonup-windows (and its macOS counterpart)

Actually doing this would probably requiring refactoring the autodiscovery code though, such that the discovery & installation strategy used by ensure_python can be chosen at import time based on the platform.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:19 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
uranusjrcommented, Jul 14, 2018

A summary of the current situation:

  • PATH-based discovery and pyenv discovery is unchanged.
  • A py.exe-based discovery has been implemented on Windows. As long as py.exe is present in PATH, --python=X.Y will consult it to discover Python installations. This has some minor restrictions (not able to discover WOW6432 installations, for example).
  • A standalone library, pythonfinder, has been developed aiming to replace the current strategy. The integration is in progress, but is far from being finished. (I feel maybe we should scale the integration effort back a little, and use it only for discovery for now).
  • pyenv is still the only option available for auto-installation. I did a minor rewrite in #2572, but there’s no change in functionality.
1reaction
uranusjrcommented, Jan 1, 2018

@ncoghlan Wow, I’ve been thinking about the same refactoring as well, and even came up with the same submodule name 😅 Glad to know I was on the right track.

The problem I have with the current implementation it that, it might not be able to integrate PEP 514. If I read the PEP correctly, it allows a distribution to use an arbitrary executable name (with InstallPath\ExecutablePath). For PythonCore (i.e. installers from python.org) it is always InstallPath + \python.exe, but that might not be the case for other distributions. I’m not aware of any distributions/implementations using a different executable name (Anaconda also uses python.exe, and pypy doesn’t implement PEP 514 at all), but it might be better to be more future-proof.

My thought is to implement multiple finders:

  • pipenv.pythonfinders.GlobalPythonFinder: Look for python, pythonX, and pythonX.Y in PATH, and call it to check whether it has the right version.
  • pipenv.pythonfinders.PyEnvFinder: Look for a matching version from pyenv.
  • pipenv.pythonfinders.PEP514Finder: Look for a matching version in the registry.

When the user calls get_runtime_path(), it detects what finder(s) to use. If pyenv is installed (i.e. the right environs are set), use PyEnvFinder and GlobalPythonFinder; if on Windows, use PEP514Finder and GlobalPythonFinder, etc. This way we don’t need to rely on the PATH environ to find the right Python, and I think is the right level of abstraction.

P.S. In regard of install_runtime, I’m currently working on a Python version-management tool for Windows (uranusjr/snafu). The idea is to abstract away the download, install, configure part of installing Python on Windows, so the user can manage multiple Python installations with minimal fuss. It plays a similar role as pyenv, but instead of building just use the official binaries. This could be useful if Pipenv wants to provide auto installation on Windows.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Runtime Metrics - Datadog Docs
Gain additional insights into your Python application's performance with the runtime metrics associated to your traces.
Read more >
Using Python for scripting and automation | Microsoft Learn
How to get started using Python for scripting, automation, and systems administration on Windows.
Read more >
Python on Windows FAQ — Python 3.11.1 documentation
Run-time linking greatly simplifies link options; everything happens at run time. Your code must load pythonNN.dll using the Windows LoadLibraryEx() routine.
Read more >
How to install and use Exchangelib Python - ActiveState
Click to install and use exchangelib Python library to work with Microsoft Exchange Web Services (EWS).
Read more >
dart github
GitHub - unit8co/darts: A python library for … ... In the window that appears select the "Tags" option and choose the highest version...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found