Options to improve Python runtime autodiscovery on Windows
See original GitHub issuePipenv currently has two Python runtime discovery and/or installation strategies:
- Search
PATH
(inpipenv.cli.find_a_system_python
), adding anypyenv
environments to the end before it does so - Install it with
pyenv
(inpipenv.cli.ensure_python
)
This misses a few potential possibilities for improvement on Windows:
- Discovery based on the Windows launcher configuration file (https://docs.python.org/3/using/windows.html#customization)
- Discovery based on the Windows registry (https://github.com/zooba/pep514tools#usage)
- Supporting
conda
based automatic Python installation in addition topyenv
installation - 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:
- Created 6 years ago
- Comments:19 (16 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A summary of the current situation:
py.exe
-based discovery has been implemented on Windows. As long aspy.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).@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
). ForPythonCore
(i.e. installers from python.org) it is alwaysInstallPath
+\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 usespython.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 forpython
,pythonX
, andpythonX.Y
inPATH
, 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), usePyEnvFinder
andGlobalPythonFinder
; if on Windows, usePEP514Finder
andGlobalPythonFinder
, etc. This way we don’t need to rely on thePATH
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.