Skip to content

uv pip wont accept my requirements file #2276

Closed

Description

@yashranjan1

The command I wrote:

uv pip install -r .\requirements.txt

The result:

error: failed to read from file `.\requirements.txt`
  Caused by: stream did not contain valid UTF-8

The requirements file:

annotated-types==0.6.0
anyio==4.3.0
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
click==8.1.7
colorama==0.4.6
cryptography==42.0.5
exceptiongroup==1.2.0
fastapi==0.110.0
h11==0.14.0
idna==3.6
pycparser==2.21
pydantic==2.6.3
pydantic-core==2.16.3
python-dotenv==1.0.1
requests==2.31.0
sniffio==1.3.1
starlette==0.36.3
typing-extensions==4.10.0
urllib3==2.2.1
uvicorn==0.27.1

Current UV version:

Yash ❯❯ uv --version
uv 0.1.15 (a8ac7b1eb 2024-03-05)

Operating System: Windows

This works when I use pip but not with UV. I tried to look for a similar issue but couldn't find one. If this is a duplicate, I apologise. Would you be so kind to give me a link to the issue where the solution for this is discussed? Thanks!

Activity

  1. BurntSushi commented on Mar 7, 2024

    @BurntSushi
    Member

    Can you upload an exact copy of your requirements.txt as an attachment? My hunch is that it's UTF-16 or otherwise contains invalid UTF-8 based on the error message you're getting.

  2. added
    needs-mre
    on Mar 7, 2024
  3. yashranjan1 commented on Mar 7, 2024

    @yashranjan1
    Author

    My requirements file -> requirements.txt

    I had uv write this out for me using the command:

    uv pip freeze > requirements.txt
    
  4. BurntSushi commented on Mar 7, 2024

    @BurntSushi
    Member

    Can you share the original requirements.txt? The one that produced the error in the original issue.

  5. yashranjan1 commented on Mar 7, 2024

    @yashranjan1
    Author

    That is the one, I installed the packages myself using uv and then i created a requirements file so other people can run my program on their computers as well

  6. notatallshaw commented on Mar 7, 2024

    @notatallshaw
    Collaborator

    My requirements file -> requirements.txt

    I had uv write this out for me using the command:

    uv pip freeze > requirements.txt
    

    No idea on the cause, but FYI this file is "UTF-16 LE BOM" , not "UTF-8".

  7. BurntSushi commented on Mar 7, 2024

    @BurntSushi
    Member

    Oh interesting, okay, thank you. Sorry, I misunderstood. I can actually reproduce the problem:

    $ curl -sLO 'https://github.com/astral-sh/uv/files/14526633/requirements.txt'
    
    $ uv venv
    Using Python 3.11.6 interpreter at: /usr/bin/python3
    Creating virtualenv at: .venv
    Activate with: source .venv/bin/activate
    
    $ uv pip install -r requirements.txt
    error: failed to read from file `requirements.txt`
      Caused by: stream did not contain valid UTF-8
    

    So the file is indeed UTF-16. Specifically, it starts with a 0xFF 0xFE byte order mark, which indicates UTF-16 little endian:

    $ iconv -futf8 -tutf8 requirements.txt
    iconv: illegal input sequence at position 0
    
    $ iconv -futf16be -tutf8 requirements.txt
    �愀渀渀漀琀愀琀攀搀ⴀ琀礀瀀攀猀㴀㴀 ⸀㘀⸀ ഀ਀愀渀礀椀漀㴀㴀㐀⸀㌀⸀ ഀ਀挀攀爀琀椀昀椀㴀㴀㈀ ㈀㐀⸀㈀⸀㈀ഀ਀挀昀昀椀㴀㴀㄀⸀㄀㘀⸀ ഀ਀挀栀愀爀猀攀琀ⴀ渀漀爀洀愀氀椀稀攀爀㴀㴀㌀⸀㌀⸀㈀ഀ਀挀氀椀挀欀㴀㴀㠀⸀㄀⸀㜀ഀ਀挀漀氀漀爀愀洀愀㴀㴀 ⸀㐀⸀㘀ഀ਀挀爀礀瀀琀漀 最爀愀瀀栀礀㴀㴀㐀㈀⸀ ⸀㔀ഀ਀攀砀挀攀瀀琀椀漀渀最爀漀甀瀀㴀㴀㄀⸀㈀⸀ ഀ਀昀愀猀琀愀瀀椀㴀㴀 ⸀㄀㄀ ⸀ ഀ਀栀㄀㄀㴀㴀 ⸀㄀㐀⸀ ഀ਀椀搀渀愀㴀㴀㌀⸀㘀ഀ਀瀀礀挀瀀愀爀猀攀爀㴀㴀㈀⸀㈀㄀ഀ਀瀀礀搀愀渀琀椀挀㴀㴀㈀⸀㘀⸀㌀ഀ਀瀀礀搀愀渀琀椀挀ⴀ挀漀爀攀㴀㴀㈀⸀㄀㘀⸀㌀ഀ਀瀀 礀琀栀漀渀ⴀ搀漀琀攀渀瘀㴀㴀㄀⸀ ⸀㄀ഀ਀爀攀焀甀攀猀琀猀㴀㴀㈀⸀㌀㄀⸀ ഀ਀猀渀椀昀昀椀漀㴀㴀㄀⸀㌀⸀㄀ഀ਀猀琀愀爀氀攀琀琀攀㴀㴀 ⸀㌀㘀⸀㌀ഀ਀琀礀瀀椀渀最ⴀ攀砀琀攀渀猀椀漀渀猀㴀㴀㐀⸀㄀ ⸀ ഀ਀甀爀氀氀椀戀㌀㴀㴀㈀⸀㈀⸀㄀ഀ਀甀瘀椀挀漀爀渀㴀㴀 ⸀㈀㜀⸀㄀ഀ਀%
    
    $ iconv -futf16le -tutf8 requirements.txt
    annotated-types==0.6.0
    anyio==4.3.0
    certifi==2024.2.2
    cffi==1.16.0
    charset-normalizer==3.3.2
    click==8.1.7
    colorama==0.4.6
    cryptography==42.0.5
    exceptiongroup==1.2.0
    fastapi==0.110.0
    h11==0.14.0
    idna==3.6
    pycparser==2.21
    pydantic==2.6.3
    pydantic-core==2.16.3
    python-dotenv==1.0.1
    requests==2.31.0
    sniffio==1.3.1
    starlette==0.36.3
    typing-extensions==4.10.0
    urllib3==2.2.1
    uvicorn==0.27.1
    

    And xxd confirms:

    $ xxd requirements.txt
    00000000: fffe 6100 6e00 6e00 6f00 7400 6100 7400  ..a.n.n.o.t.a.t.
    00000010: 6500 6400 2d00 7400 7900 7000 6500 7300  e.d.-.t.y.p.e.s.
    00000020: 3d00 3d00 3000 2e00 3600 2e00 3000 0d00  =.=.0...6...0...
    00000030: 0a00 6100 6e00 7900 6900 6f00 3d00 3d00  ..a.n.y.i.o.=.=.
    00000040: 3400 2e00 3300 2e00 3000 0d00 0a00 6300  4...3...0.....c.
    00000050: 6500 7200 7400 6900 6600 6900 3d00 3d00  e.r.t.i.f.i.=.=.
    00000060: 3200 3000 3200 3400 2e00 3200 2e00 3200  2.0.2.4...2...2.
    00000070: 0d00 0a00 6300 6600 6600 6900 3d00 3d00  ....c.f.f.i.=.=.
    00000080: 3100 2e00 3100 3600 2e00 3000 0d00 0a00  1...1.6...0.....
    00000090: 6300 6800 6100 7200 7300 6500 7400 2d00  c.h.a.r.s.e.t.-.
    000000a0: 6e00 6f00 7200 6d00 6100 6c00 6900 7a00  n.o.r.m.a.l.i.z.
    000000b0: 6500 7200 3d00 3d00 3300 2e00 3300 2e00  e.r.=.=.3...3...
    000000c0: 3200 0d00 0a00 6300 6c00 6900 6300 6b00  2.....c.l.i.c.k.
    000000d0: 3d00 3d00 3800 2e00 3100 2e00 3700 0d00  =.=.8...1...7...
    000000e0: 0a00 6300 6f00 6c00 6f00 7200 6100 6d00  ..c.o.l.o.r.a.m.
    000000f0: 6100 3d00 3d00 3000 2e00 3400 2e00 3600  a.=.=.0...4...6.
    00000100: 0d00 0a00 6300 7200 7900 7000 7400 6f00  ....c.r.y.p.t.o.
    00000110: 6700 7200 6100 7000 6800 7900 3d00 3d00  g.r.a.p.h.y.=.=.
    00000120: 3400 3200 2e00 3000 2e00 3500 0d00 0a00  4.2...0...5.....
    00000130: 6500 7800 6300 6500 7000 7400 6900 6f00  e.x.c.e.p.t.i.o.
    00000140: 6e00 6700 7200 6f00 7500 7000 3d00 3d00  n.g.r.o.u.p.=.=.
    00000150: 3100 2e00 3200 2e00 3000 0d00 0a00 6600  1...2...0.....f.
    00000160: 6100 7300 7400 6100 7000 6900 3d00 3d00  a.s.t.a.p.i.=.=.
    00000170: 3000 2e00 3100 3100 3000 2e00 3000 0d00  0...1.1.0...0...
    00000180: 0a00 6800 3100 3100 3d00 3d00 3000 2e00  ..h.1.1.=.=.0...
    00000190: 3100 3400 2e00 3000 0d00 0a00 6900 6400  1.4...0.....i.d.
    000001a0: 6e00 6100 3d00 3d00 3300 2e00 3600 0d00  n.a.=.=.3...6...
    000001b0: 0a00 7000 7900 6300 7000 6100 7200 7300  ..p.y.c.p.a.r.s.
    000001c0: 6500 7200 3d00 3d00 3200 2e00 3200 3100  e.r.=.=.2...2.1.
    000001d0: 0d00 0a00 7000 7900 6400 6100 6e00 7400  ....p.y.d.a.n.t.
    000001e0: 6900 6300 3d00 3d00 3200 2e00 3600 2e00  i.c.=.=.2...6...
    000001f0: 3300 0d00 0a00 7000 7900 6400 6100 6e00  3.....p.y.d.a.n.
    00000200: 7400 6900 6300 2d00 6300 6f00 7200 6500  t.i.c.-.c.o.r.e.
    00000210: 3d00 3d00 3200 2e00 3100 3600 2e00 3300  =.=.2...1.6...3.
    00000220: 0d00 0a00 7000 7900 7400 6800 6f00 6e00  ....p.y.t.h.o.n.
    00000230: 2d00 6400 6f00 7400 6500 6e00 7600 3d00  -.d.o.t.e.n.v.=.
    00000240: 3d00 3100 2e00 3000 2e00 3100 0d00 0a00  =.1...0...1.....
    00000250: 7200 6500 7100 7500 6500 7300 7400 7300  r.e.q.u.e.s.t.s.
    00000260: 3d00 3d00 3200 2e00 3300 3100 2e00 3000  =.=.2...3.1...0.
    00000270: 0d00 0a00 7300 6e00 6900 6600 6600 6900  ....s.n.i.f.f.i.
    00000280: 6f00 3d00 3d00 3100 2e00 3300 2e00 3100  o.=.=.1...3...1.
    00000290: 0d00 0a00 7300 7400 6100 7200 6c00 6500  ....s.t.a.r.l.e.
    000002a0: 7400 7400 6500 3d00 3d00 3000 2e00 3300  t.t.e.=.=.0...3.
    000002b0: 3600 2e00 3300 0d00 0a00 7400 7900 7000  6...3.....t.y.p.
    000002c0: 6900 6e00 6700 2d00 6500 7800 7400 6500  i.n.g.-.e.x.t.e.
    000002d0: 6e00 7300 6900 6f00 6e00 7300 3d00 3d00  n.s.i.o.n.s.=.=.
    000002e0: 3400 2e00 3100 3000 2e00 3000 0d00 0a00  4...1.0...0.....
    000002f0: 7500 7200 6c00 6c00 6900 6200 3300 3d00  u.r.l.l.i.b.3.=.
    00000300: 3d00 3200 2e00 3200 2e00 3100 0d00 0a00  =.2...2...1.....
    00000310: 7500 7600 6900 6300 6f00 7200 6e00 3d00  u.v.i.c.o.r.n.=.
    00000320: 3d00 3000 2e00 3200 3700 2e00 3100 0d00  =.0...2.7...1...
    00000330: 0a00                                     ..
    

    When writing to a console, Rust will write data as UTF-16. Since you're piping the output via stdout, this is indeed the code path being exercised.

    So I think the solution to this is for uv to transparently accept UTF-16 encoded files in addition to UTF-8 encoded files.

  8. added
    bug
    on Mar 7, 2024
  9. self-assigned this
    on Mar 7, 2024
  10. removed
    needs-mre
    on Mar 7, 2024
  11. yashranjan1 commented on Mar 7, 2024

    @yashranjan1
    Author

    Thanks for the explanation and the prompt response Please do tag me on the PR for fixing this issue!

  12. zanieb commented on Mar 7, 2024

    @zanieb
    Member

    @BurntSushi we previously said we would not change this behavior:

    We could still change our mind though.

  13. added a commit that references this issue on Mar 8, 2024
    b3b5afa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions