uv再体验
UV usage
I have wrote an article on Jan.18.2025 .In that article I thought uv is not a useful tool as I thought. However, here in this time I will say “Nothing is better than UV”.
UV is all you need
Install & Uninstall
In windows, we can download and install uv with a standalone installer.
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Then you can use it anywhere.
When uv is installed via the standalone installer, it can update itself on-demand:
uv self update
You can use
$ uv pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
install stable, CPU-only PyTorch on Windows.
上面的方式并不可行。
建议还是使用官方建议的操作进行食用。
ModuleNotFoundError: No module named ‘pkg_resources’
这个问题并不会出现在conda中,但却在uv使用的时候出现了,并且在经历了一个劲的钻牛角尖后我终于知道并不是安装包的问题了,而是缺少一个依赖,setuptools,我猜测可能是我将makeupsafe降级了之后这个安装包受损导致的。
(xpu-test) root@DESKTOP-SN2FD5H:~/xpu_test# python -c "import torch; import intel_extension_for_pytorch as ipex; print(torch.__version__); print(ipex.__version__);"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/root/xpu_test/.venv/lib/python3.11/site-packages/intel_extension_for_pytorch/__init__.py", line 120, in <module>
from . import llm
File "/root/xpu_test/.venv/lib/python3.11/site-packages/intel_extension_for_pytorch/llm/__init__.py", line 2, in <module>
from .frontend import optimize
File "/root/xpu_test/.venv/lib/python3.11/site-packages/intel_extension_for_pytorch/llm/frontend.py", line 1, in <module>
from intel_extension_for_pytorch.transformers.optimize import optimize
File "/root/xpu_test/.venv/lib/python3.11/site-packages/intel_extension_for_pytorch/transformers/__init__.py", line 1, in <module>
from .optimize import optimize_transformers
File "/root/xpu_test/.venv/lib/python3.11/site-packages/intel_extension_for_pytorch/transformers/optimize.py", line 4, in <module>
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
(xpu-test) root@DESKTOP-SN2FD5H:~/xpu_test# uv add pkg_resources
× No solution found when resolving dependencies for split ((python_full_version >= '3.12' and platform_machine != 'aarch64' and sys_platform == 'linux') or
│ (python_full_version >= '3.12' and sys_platform != 'darwin' and sys_platform != 'linux')):
╰─▶ Because there are no versions of pkg-resources and your project depends on pkg-resources, we can conclude that your project's requirements are unsatisfiable.
help: If you want to add the package regardless of the failed resolution, provide the `--frozen` flag to skip locking and syncing.
(xpu-test) root@DESKTOP-SN2FD5H:~/xpu_test# uv pip install pkg_resources
× No solution found when resolving dependencies:
╰─▶ Because there are no versions of pkg-resources and you require pkg-resources, we can conclude that your requirements are unsatisfiable.
(xpu-test) root@DESKTOP-SN2FD5H:~/xpu_test# uv add setuptools
Resolved 21 packages in 6.23s
Prepared 1 package in 9.65s
Installed 1 package in 48ms
+ setuptools==70.2.0
(xpu-test) root@DESKTOP-SN2FD5H:~/xpu_test# python -c "import torch; import intel_extension_for_pytorch as ipex; print(torch.__version__); print(ipex.__version__);"
2.5.0+cpu
2.5.0+cpu
还有一个简单的测试安装是否成功的脚本
()
下面是我以后的安装模板,其中pytorch的安装源可能要换成cuda版本。
[]
= "xpu-test"
= "0.1.0"
= "Add your description here"
= "README.md"
= ">=3.11"
= [
"intel-extension-for-pytorch==2.5.0",
"markupsafe==2.1.3",
"medpy>=0.5.2",
"oneccl-bind-pt==2.5.0",
"opencv-python>=4.11.0.86",
"setuptools>=70.2.0",
"tensorboard>=2.18.0",
"torch==2.5.0",
"torchaudio==2.5.0",
"torchvision==0.20.0",
"yacs>=0.1.8",
]
# 换源以及加上软链接,这个是非常必要的,防止占用空间。。。
[]
= "symlink"
= "https://pypi.tuna.tsinghua.edu.cn/simple"
# UV官方文档所建议的安装程序。
[]
={ = 'torch-intel'}
={ = 'torch-intel'}
= [
{ = "pytorch-cpu" },
]
= [
{ = "pytorch-cpu" },
]
[[]]
= "torch-intel"
= "https://pytorch-extension.intel.com/release-whl/stable/cpu/us"
= true
[[]]
= "pytorch-cpu"
= "https://download.pytorch.org/whl/cpu"
= true
# [[index]]
# url = "https://test.pypi.org/simple"
# default = true
# [tool.uv.pip]
关于一个报错
这个错误在uv/issues/10843 得到解决,删除lock文件即可,但不知道这个是否为最优做法。
关于之前的一个报错,就是无法从镜像源里面下载torch
[]
={ = 'torch-intel'}
={ = 'torch-intel'}
= [
{ = "pytorch-cpu" },
]
= [
{ = "pytorch-cpu" },
]
[[]]
= "torch-intel"
= "https://pytorch-extension.intel.com/release-whl/stable/cpu/us"
= true
[[]]
= "pytorch-cpu"
= "https://download.pytorch.org/whl/cpu"
= true
如果单纯使用这套模板会报错,并不会正确在阿里云里面下载torch,如果改掉了url的话,而应该在tool.uv里面添加一个find-links参数,这样就能有效的解决问题。
[]
= "symlink"
= "https://pypi.tuna.tsinghua.edu.cn/simple"
= "https://mirrors.aliyun.com/pytorch-wheels/cu118"
参考:
Can’t use tkinter with new venv set up with uv
参考:
=
=
=
=
在所需要的代码里面加上这段即可。