uv icon indicating copy to clipboard operation
uv copied to clipboard

Virtualenv creation is failing on Python embedded versions

Open Pixel-Minions opened this issue 1 year ago • 5 comments

Hi,

When I try to create a virtualenv from a Python Embedded version on Windows I get the following error:

Using Python 3.7.9 interpreter at C:\Users\alex\Documents\Python\python-3.7.9-embed-amd64\python.exe
Creating virtualenv at: .venv
uv::venv::creation

  x Failed to create virtualenv
  |-> failed to copy file from C:\Users\alex\Documents\Python\python-3.7.9-embed-amd64\Lib\venv\scripts\nt\python.exe
  |   to \\?\D:\testing\uv\.venv\Scripts\python.exe
  `-> The system cannot find the path specified. (os error 3)

The path: C:\Users\alex\Documents\Python\python-3.7.9-embed-amd64\Lib\venv\scripts\nt\python.exe doesn't exist.

The error is happening on Windows 10 and uv-0.1.4.

How to recreate the issue:

  1. Download an embedded version of Python.
  2. Unzip it on any folder.
  3. Append it to the PATH and make sure it is the Python version by default.
  4. run uv venv.
  5. Fails.

Best,

Pixel-Minions avatar Feb 18 '24 16:02 Pixel-Minions

Hey guys,

I wonder if there is any plans to support embedded version, I would really like to bring UV to the company and replace all the libraries we have with Poetry, but sadly, without being able to work with embedded versions, it seems like it won't work.

Pixel-Minions avatar Feb 26 '24 16:02 Pixel-Minions

What exactly do you mean by embedded version of python, could you link me to a download page?

konstin avatar Feb 26 '24 17:02 konstin

https://www.python.org/ftp/python/3.11.8/python-3.11.8-embed-amd64.zip

https://www.python.org/downloads/release/python-3118/

@konstin

Pixel-Minions avatar Feb 26 '24 17:02 Pixel-Minions

Thanks!

I've checked with virtualenv and apparently the strategy for supporting embeddable python version is to check for the shim and if it doesn't exist, copy all files: https://github.com/pypa/virtualenv/blob/cad550030ae77e181a1d7c328742a97f2880ef9b/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py#L58-L68

konstin avatar Feb 27 '24 13:02 konstin

When running uv.exe venv testvenv --python .\python-3.11.8-embed-amd64\python.exe, I get

Using Python 3.11.8 interpreter at: python-3.11.8-embed-amd64\python.exe
Creating virtualenv at: testvenv
uv::venv::creation

  x Failed to create virtualenv
  |-> failed to copy file from \\?\C:\Users\simlin1\Downloads\python-3.11.8-embed-amd64\venvwlauncher.exe to
  |   \\?\C:\Users\simlin1\Downloads\testvenv\Scripts\python.exe
  `-> Det går inte att hitta filen. (os error 2)       

swz-git avatar Mar 29 '24 19:03 swz-git

Yep, same error here. It seems uv is expecting specific files to be there. With virtualenv, there is no problem however.

Pixel-Minions avatar Apr 19 '24 14:04 Pixel-Minions

For starters can we get a minimal reproducible example for this? Like a Dockerfile that I can run to understand the current behavior and what the structure of these embedded Pythons looks like?

charliermarsh avatar Apr 19 '24 15:04 charliermarsh

I can reproduce this when downloading the embedded python from (https://www.python.org/ftp/python/3.11.8/python-3.11.8-embed-amd64.zip) and using it for uv venv -p path\to\embedded\python. The embedded python i looked at was a flat directory which we need to copy to support this.

konstin avatar Apr 19 '24 16:04 konstin

I think I see what needs to be changed, and it looks relatively (?) straightforward. Though there are some comments from Paul Moore around this not being an intended use-case for the embedded distribution: https://github.com/pypa/virtualenv/issues/2368#issuecomment-1168574713.

charliermarsh avatar Apr 20 '24 03:04 charliermarsh

Can anyone just clarify for me what the motivating use-case is for using the embedded Pythons here?

charliermarsh avatar Apr 20 '24 03:04 charliermarsh

The comment you mentioned makes sense, there are ways around to create portable versions of python that might work with uv. I will try the nuget or winpython.

The reason for the embedded version is that, after some minor changes to the .pht file and using virtualenv, you can create portable virtual environment, it doesn't get linked to the interpreter source like if you would use a standard Python installation.

Pixel-Minions avatar Apr 20 '24 05:04 Pixel-Minions

I added virtualenv-like support in https://github.com/astral-sh/uv/pull/3161.

charliermarsh avatar Apr 20 '24 22:04 charliermarsh