learn with python-第九章:元组

本文深入探讨了Python中的元组类型及其操作方法,包括不可变性、赋值和交换变量等特性,并介绍了如何使用元组进行数据传递。此外,文章还详细解释了Python的随机数生成机制,包括使用`random`模块来产生不同范围内的随机数,为程序增加不确定性。
第九章:元组
9.1易变性和元组
目前为止,我们接触了两种复合类型:由字符组成的字符串,以及由多重数据类型组成的列表,两者的区别在于列表中的元素可以变,而字符串中的字符不能变,换句话来说就是列表可变,字符串不可变。
python中有另外一种类型和list类似,但是其不可变,这种类型称之为tuple,语法上tuple是一串逗号分隔的值列表
>>> tuple = 'a', 'b', 'c', 'd', 'e'
我们也可以将tuple值用括号包起来,创建只包含一个元素的tuple必须加上最后一个逗号,否则会当成是一个字符串。
>>> t1 = ('a',)
除了语法之外,元祖的操作同列表的操作完全一样,通过下标从元祖获取元素
>>> tuple = ('a', 'b', 'c', 'd', 'e')
>>> tuple[0]
'a'
分片操作获取元祖中的部分值
>>> tuple[1:3]
('b', 'c')
但是如果我们尝试改变元祖中的某个值,会抛出一个错误
>>> tuple[0] = 'A'
TypeError: object doesn't support item assignment
虽然我们不能改变元祖的元素,但是我们可以新建一个元祖替换
>>> tuple = ('A',) + tuple[1:]
>>> tuple
('A', 'b', 'c', 'd', 'e')

9.2元祖赋值
有时,我们需要交换两个变量的值,我们通过一个临时变量进行交换:
>>> temp = a
>>> a = b
>>> b = temp
但是如果程序中有大量类似的代码会显得臃肿,python提供了一个元组操作为这种操作提供了便捷的方式
>>> a, b = b, a
左边是元组变量,右边是元组的值,每个值都被分配给对应的变量,游标的表达式在赋值开始之前都会被计算出值
这种特性为元组的赋值提供了非常大的便利性。左边的变量数目必须和右边值得数目相同。

9.3将元组作为返回值
函数可以将元组作为返回值返回,例如:下面函数交换两个参数
def swap(x, y):
return y, x
我们可以把返回值赋值给两个变量:
a, b = swap(a, b)

9.4随机数
大部分的计算机对于同一种情况只能进行同一种操作,因此被称之为是确定性的,确定通常是一件好事情,我们期望相同的条件下每次计算的结果都相同,对于某些情况,我们却需要计算机表现出一定的不确定性,游戏就是一个显著的例子,除此之外还有很多情况。
要使一个程序变得完全不确定性并不容易,但是让其看起来不确定却不难,python提供了内置的函数产生随机数,在数学的中,这些数字并不是随机的,但是我们可以认为其是随机的。
random模块中包含函数random返回一个0.0到1.0之间的随机数,每次调用random方法都会得到一个伪随机数
import random
    for i in range(10):
        x = random.random()
        print x
如果需要产生一个更大边界的随机数,我们可以用随机数乘以这个边界值

PS C:\Users\Administrator\Desktop> # 查看 E:\AI_System 目录的结构 PS C:\Users\Administrator\Desktop> Get-ChildItem E:\AI_System -Recurse -Depth 2 | Where-Object {$_.PSIsContainer} | Select-Object FullName FullName -------- E:\AI_System\agent E:\AI_System\AI_Core_Functional E:\AI_System\cache E:\AI_System\cognitive_arch E:\AI_System\config E:\AI_System\core E:\AI_System\data E:\AI_System\environment E:\AI_System\logs E:\AI_System\models E:\AI_System\model_cache E:\AI_System\model_manager E:\AI_System\model_server E:\AI_System\scripts E:\AI_System\security E:\AI_System\temp E:\AI_System\utils E:\AI_System\venv E:\AI_System\web_ui E:\AI_System\agent\affective_modules E:\AI_System\agent\cognitive_system E:\AI_System\agent\conscious_system E:\AI_System\agent\decision_system E:\AI_System\agent\generated_images E:\AI_System\agent\knowledge_system E:\AI_System\agent\models E:\AI_System\agent\tests E:\AI_System\agent\text_results E:\AI_System\agent\utils E:\AI_System\agent\__pycache__ E:\AI_System\agent\affective_modules\__pycache__ E:\AI_System\agent\conscious_system\cognitive E:\AI_System\agent\conscious_system\layers E:\AI_System\agent\conscious_system\logs E:\AI_System\agent\conscious_system\memory E:\AI_System\agent\conscious_system\perception E:\AI_System\agent\conscious_system\states E:\AI_System\agent\conscious_system\__pycache__ E:\AI_System\agent\decision_system\__pycache__ E:\AI_System\agent\models\__pycache__ E:\AI_System\agent\utils\__pycache__ E:\AI_System\cognitive_arch\__pycache__ E:\AI_System\config\__pycache__ E:\AI_System\core\__pycache__ E:\AI_System\data\environment E:\AI_System\environment\__pycache__ E:\AI_System\models\cache E:\AI_System\model_manager\__pycache__ E:\AI_System\model_server\agent_system E:\AI_System\model_server\config E:\AI_System\model_server\core E:\AI_System\model_server\generated_images E:\AI_System\model_server\models E:\AI_System\model_server\resources E:\AI_System\model_server\services E:\AI_System\model_server\ui_components E:\AI_System\model_server\utils E:\AI_System\model_server\__pycache__ E:\AI_System\model_server\agent_system\core E:\AI_System\model_server\agent_system\interaction E:\AI_System\model_server\agent_system\__pycache__ E:\AI_System\model_server\core\__pycache__ E:\AI_System\model_server\resources\icons E:\AI_System\model_server\resources\styles E:\AI_System\security\__pycache__ E:\AI_System\utils\__pycache__ E:\AI_System\venv\Include E:\AI_System\venv\Lib E:\AI_System\venv\Scripts E:\AI_System\venv\share E:\AI_System\venv\Lib\site-packages E:\AI_System\venv\share\man E:\AI_System\web_ui\# E:\AI_System\web_ui\flagged E:\AI_System\web_ui\static E:\AI_System\web_ui\templates E:\AI_System\web_ui\venv E:\AI_System\web_ui\__pycache__ E:\AI_System\web_ui\#\Include E:\AI_System\web_ui\#\Lib E:\AI_System\web_ui\#\Scripts E:\AI_System\web_ui\static\css E:\AI_System\web_ui\static\images E:\AI_System\web_ui\static\js E:\AI_System\web_ui\venv\Include E:\AI_System\web_ui\venv\Lib E:\AI_System\web_ui\venv\Scripts E:\AI_System\web_ui\venv\share PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 特别检查是否有 core 目录 PS C:\Users\Administrator\Desktop> Get-ChildItem E:\AI_System\core -ErrorAction SilentlyContinue 目录: E:\AI_System\core Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2025/8/17 10:32 __pycache__ -a---- 2025/8/17 0:05 6643 circuit_breaker.py -a---- 2025/8/17 10:31 2711 config.py -a---- 2025/8/17 0:05 3002 config_loader.py -a---- 2025/8/17 0:05 1214 decision_engine.py -a---- 2025/8/17 0:05 563 dependency_manager.py -a---- 2025/8/17 0:05 8464 environment.py -a---- 2025/8/17 0:05 195 environment_interface.py -a---- 2025/8/17 0:05 16338 exceptions.py -a---- 2025/8/17 0:05 3 genetic_code.py -a---- 2025/8/17 0:05 1375 metrics.py -a---- 2025/8/17 0:05 578 models.py -a---- 2025/8/17 23:58 1683 module_loader.py -a---- 2025/8/17 0:05 1380 relationship_manager.py -a---- 2025/8/17 0:05 10957 subsystem_registry.py -a---- 2025/8/17 0:05 1945 system_components.py -a---- 2025/8/17 2:20 5770 __init__.py PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 检查是否有 model_loader.py 文件 PS C:\Users\Administrator\Desktop> Get-ChildItem E:\AI_System\core\model_loader.py -ErrorAction SilentlyContinue PS C:\Users\Administrator\Desktop> # 安装可能需要的额外依赖 PS C:\Users\Administrator\Desktop> python -m pip install modelscope # 根据警告信息,可能需要这个 WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Requirement already satisfied: modelscope in e:\python310\lib\site-packages (1.29.0) Requirement already satisfied: filelock in e:\python310\lib\site-packages (from modelscope) (3.18.0) Requirement already satisfied: requests>=2.25 in e:\python310\lib\site-packages (from modelscope) (2.32.4) Requirement already satisfied: setuptools in e:\python310\lib\site-packages (from modelscope) (80.9.0) Requirement already satisfied: tqdm>=4.64.0 in e:\python310\lib\site-packages (from modelscope) (4.67.1) Requirement already satisfied: urllib3>=1.26 in e:\python310\lib\site-packages (from modelscope) (2.5.0) Requirement already satisfied: charset_normalizer<4,>=2 in e:\python310\lib\site-packages (from requests>=2.25->modelscope) (3.4.2) Requirement already satisfied: idna<4,>=2.5 in e:\python310\lib\site-packages (from requests>=2.25->modelscope) (3.10) Requirement already satisfied: certifi>=2017.4.17 in e:\python310\lib\site-packages (from requests>=2.25->modelscope) (2025.8.3) Requirement already satisfied: colorama in e:\python310\lib\site-packages (from tqdm>=4.64.0->modelscope) (0.4.6) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) PS C:\Users\Administrator\Desktop> python -m pip install transformers[torch] # 确保 transformers 与 torch 兼容 WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Requirement already satisfied: transformers[torch] in e:\python310\lib\site-packages (4.31.0) Requirement already satisfied: filelock in e:\python310\lib\site-packages (from transformers[torch]) (3.18.0) Requirement already satisfied: huggingface-hub<1.0,>=0.14.1 in e:\python310\lib\site-packages (from transformers[torch]) (0.34.3) Requirement already satisfied: numpy>=1.17 in e:\python310\lib\site-packages (from transformers[torch]) (1.26.4) Requirement already satisfied: packaging>=20.0 in e:\python310\lib\site-packages (from transformers[torch]) (25.0) Requirement already satisfied: pyyaml>=5.1 in e:\python310\lib\site-packages (from transformers[torch]) (6.0.2) Requirement already satisfied: regex!=2019.12.17 in e:\python310\lib\site-packages (from transformers[torch]) (2025.7.34) Requirement already satisfied: requests in e:\python310\lib\site-packages (from transformers[torch]) (2.32.4) Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in e:\python310\lib\site-packages (from transformers[torch]) (0.13.3) Requirement already satisfied: safetensors>=0.3.1 in e:\python310\lib\site-packages (from transformers[torch]) (0.5.3) Requirement already satisfied: tqdm>=4.27 in e:\python310\lib\site-packages (from transformers[torch]) (4.67.1) Requirement already satisfied: torch!=1.12.0,>=1.9 in e:\python310\lib\site-packages (from transformers[torch]) (2.0.1) Requirement already satisfied: accelerate>=0.20.3 in e:\python310\lib\site-packages (from transformers[torch]) (0.21.0) Requirement already satisfied: fsspec>=2023.5.0 in e:\python310\lib\site-packages (from huggingface-hub<1.0,>=0.14.1->transformers[torch]) (2025.7.0) Requirement already satisfied: typing-extensions>=3.7.4.3 in e:\python310\lib\site-packages (from huggingface-hub<1.0,>=0.14.1->transformers[torch]) (4.14.1) Requirement already satisfied: psutil in e:\python310\lib\site-packages (from accelerate>=0.20.3->transformers[torch]) (7.0.0) Requirement already satisfied: sympy in e:\python310\lib\site-packages (from torch!=1.12.0,>=1.9->transformers[torch]) (1.13.3) Requirement already satisfied: networkx in e:\python310\lib\site-packages (from torch!=1.12.0,>=1.9->transformers[torch]) (3.4.2) Requirement already satisfied: jinja2 in e:\python310\lib\site-packages (from torch!=1.12.0,>=1.9->transformers[torch]) (3.1.6) Requirement already satisfied: colorama in e:\python310\lib\site-packages (from tqdm>=4.27->transformers[torch]) (0.4.6) Requirement already satisfied: MarkupSafe>=2.0 in e:\python310\lib\site-packages (from jinja2->torch!=1.12.0,>=1.9->transformers[torch]) (2.1.5) Requirement already satisfied: charset_normalizer<4,>=2 in e:\python310\lib\site-packages (from requests->transformers[torch]) (3.4.2) Requirement already satisfied: idna<4,>=2.5 in e:\python310\lib\site-packages (from requests->transformers[torch]) (3.10) Requirement already satisfied: urllib3<3,>=1.21.1 in e:\python310\lib\site-packages (from requests->transformers[torch]) (2.5.0) Requirement already satisfied: certifi>=2017.4.17 in e:\python310\lib\site-packages (from requests->transformers[torch]) (2025.8.3) Requirement already satisfied: mpmath<1.4,>=1.1.0 in e:\python310\lib\site-packages (from sympy->torch!=1.12.0,>=1.9->transformers[torch]) (1.3.0) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) PS C:\Users\Administrator\Desktop> python -m pip install accelerate # 用于模型加速 WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Requirement already satisfied: accelerate in e:\python310\lib\site-packages (0.21.0) Requirement already satisfied: numpy>=1.17 in e:\python310\lib\site-packages (from accelerate) (1.26.4) Requirement already satisfied: packaging>=20.0 in e:\python310\lib\site-packages (from accelerate) (25.0) Requirement already satisfied: psutil in e:\python310\lib\site-packages (from accelerate) (7.0.0) Requirement already satisfied: pyyaml in e:\python310\lib\site-packages (from accelerate) (6.0.2) Requirement already satisfied: torch>=1.10.0 in e:\python310\lib\site-packages (from accelerate) (2.0.1) Requirement already satisfied: filelock in e:\python310\lib\site-packages (from torch>=1.10.0->accelerate) (3.18.0) Requirement already satisfied: typing-extensions in e:\python310\lib\site-packages (from torch>=1.10.0->accelerate) (4.14.1) Requirement already satisfied: sympy in e:\python310\lib\site-packages (from torch>=1.10.0->accelerate) (1.13.3) Requirement already satisfied: networkx in e:\python310\lib\site-packages (from torch>=1.10.0->accelerate) (3.4.2) Requirement already satisfied: jinja2 in e:\python310\lib\site-packages (from torch>=1.10.0->accelerate) (3.1.6) Requirement already satisfied: MarkupSafe>=2.0 in e:\python310\lib\site-packages (from jinja2->torch>=1.10.0->accelerate) (2.1.5) Requirement already satisfied: mpmath<1.4,>=1.1.0 in e:\python310\lib\site-packages (from sympy->torch>=1.10.0->accelerate) (1.3.0) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) PS C:\Users\Administrator\Desktop> python -m pip install sentencepiece # 用于文本处理 WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Requirement already satisfied: sentencepiece in e:\python310\lib\site-packages (0.2.0) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) PS C:\Users\Administrator\Desktop> python -m pip install protobuf # 协议缓冲区支持 WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Requirement already satisfied: protobuf in e:\python310\lib\site-packages (6.31.1) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) PS C:\Users\Administrator\Desktop> # 查看项目是否有配置文件 PS C:\Users\Administrator\Desktop> Get-ChildItem E:\AI_System\*.json -ErrorAction SilentlyContinue PS C:\Users\Administrator\Desktop> Get-ChildItem E:\AI_System\*.yaml -ErrorAction SilentlyContinue PS C:\Users\Administrator\Desktop> Get-ChildItem E:\AI_System\*.env -ErrorAction SilentlyContinue 目录: E:\AI_System Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2025/8/11 23:18 971 .env -a---- 2025/8/8 18:10 158 EAI_System.env PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 查看项目是否有 README 或说明文档 PS C:\Users\Administrator\Desktop> Get-ChildItem E:\AI_System\README* -ErrorAction SilentlyContinue PS C:\Users\Administrator\Desktop> Get-ChildItem E:\AI_System\*.md -ErrorAction SilentlyContinue PS C:\Users\Administrator\Desktop> # 修复损坏的包安装 PS C:\Users\Administrator\Desktop> python -m pip install --upgrade pip WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Requirement already satisfied: pip in e:\python310\lib\site-packages (25.2) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) PS C:\Users\Administrator\Desktop> python -m pip check WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) opencv-python 4.12.0.88 has requirement numpy<2.3.0,>=2; python_version >= "3.9", but you have numpy 1.26.4. torchaudio 2.8.0+cpu has requirement torch==2.8.0, but you have torch 2.0.1. torchvision 0.23.0+cpu has requirement torch==2.8.0, but you have torch 2.0.1. PS C:\Users\Administrator\Desktop> python -m pip install --force-reinstall modelscope WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Collecting modelscope Downloading modelscope-1.29.0-py3-none-any.whl.metadata (40 kB) Collecting filelock (from modelscope) Downloading filelock-3.19.1-py3-none-any.whl.metadata (2.1 kB) Collecting requests>=2.25 (from modelscope) Downloading requests-2.32.5-py3-none-any.whl.metadata (4.9 kB) Collecting setuptools (from modelscope) Downloading setuptools-80.9.0-py3-none-any.whl.metadata (6.6 kB) Collecting tqdm>=4.64.0 (from modelscope) Downloading tqdm-4.67.1-py3-none-any.whl.metadata (57 kB) Collecting urllib3>=1.26 (from modelscope) Downloading urllib3-2.5.0-py3-none-any.whl.metadata (6.5 kB) Collecting charset_normalizer<4,>=2 (from requests>=2.25->modelscope) Downloading charset_normalizer-3.4.3-cp310-cp310-win_amd64.whl.metadata (37 kB) Collecting idna<4,>=2.5 (from requests>=2.25->modelscope) Downloading idna-3.10-py3-none-any.whl.metadata (10 kB) Collecting certifi>=2017.4.17 (from requests>=2.25->modelscope) Downloading certifi-2025.8.3-py3-none-any.whl.metadata (2.4 kB) Collecting colorama (from tqdm>=4.64.0->modelscope) Downloading colorama-0.4.6-py2.py3-none-any.whl.metadata (17 kB) Downloading modelscope-1.29.0-py3-none-any.whl (5.9 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.9/5.9 MB 83.5 kB/s 0:00:59 Downloading requests-2.32.5-py3-none-any.whl (64 kB) Downloading charset_normalizer-3.4.3-cp310-cp310-win_amd64.whl (107 kB) Downloading idna-3.10-py3-none-any.whl (70 kB) Downloading urllib3-2.5.0-py3-none-any.whl (129 kB) Downloading certifi-2025.8.3-py3-none-any.whl (161 kB) Downloading tqdm-4.67.1-py3-none-any.whl (78 kB) Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB) Downloading filelock-3.19.1-py3-none-any.whl (15 kB) Downloading setuptools-80.9.0-py3-none-any.whl (1.2 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 127.6 kB/s 0:00:08 WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Installing collected packages: urllib3, setuptools, idna, filelock, colorama, charset_normalizer, certifi, tqdm, requests, modelscope Attempting uninstall: urllib3 Found existing installation: urllib3 2.5.0 Uninstalling urllib3-2.5.0: Successfully uninstalled urllib3-2.5.0 Attempting uninstall: setuptools Found existing installation: setuptools 80.9.0 Uninstalling setuptools-80.9.0: Successfully uninstalled setuptools-80.9.0 Attempting uninstall: idna Found existing installation: idna 3.10 Uninstalling idna-3.10: Successfully uninstalled idna-3.10 Attempting uninstall: filelock Found existing installation: filelock 3.18.0 Uninstalling filelock-3.18.0: Successfully uninstalled filelock-3.18.0 Attempting uninstall: colorama Found existing installation: colorama 0.4.6 Uninstalling colorama-0.4.6: Successfully uninstalled colorama-0.4.6 Attempting uninstall: charset_normalizer Found existing installation: charset-normalizer 3.4.2 Uninstalling charset-normalizer-3.4.2: Successfully uninstalled charset-normalizer-3.4.2 ━━━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━ 4/10 [colorama] WARNING: The script normalizer.exe is installed in 'E:\Python310\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Attempting uninstall: certifi Found existing installation: certifi 2025.8.3 Uninstalling certifi-2025.8.3: Successfully uninstalled certifi-2025.8.3 Attempting uninstall: tqdm Found existing installation: tqdm 4.67.1 Uninstalling tqdm-4.67.1: Successfully uninstalled tqdm-4.67.1 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━━━━━━━━━ 7/10 [tqdm] WARNING: The script tqdm.exe is installed in 'E:\Python310\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Attempting uninstall: requests Found existing installation: requests 2.32.4 Uninstalling requests-2.32.4: Successfully uninstalled requests-2.32.4 Attempting uninstall: modelscope Found existing installation: modelscope 1.29.0 Uninstalling modelscope-1.29.0: Successfully uninstalled modelscope-1.29.0 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╺━━━ 9/10 [modelscope] WARNING: The script modelscope.exe is installed in 'E:\Python310\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. torchaudio 2.8.0+cpu requires torch==2.8.0, but you have torch 2.0.1 which is incompatible. torchvision 0.23.0+cpu requires torch==2.8.0, but you have torch 2.0.1 which is incompatible. Successfully installed certifi-2025.8.3 charset_normalizer-3.4.3 colorama-0.4.6 filelock-3.18.0 idna-3.10 modelscope-1.29.0 requests-2.32.5 setuptools-80.9.0 tqdm-4.67.1 urllib3-2.5.0 PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 或者尝试清理并重新安装所有依赖 PS C:\Users\Administrator\Desktop> python -m pip freeze > requirements.txt WARNING: No metadata found in e:\python310\lib\site-packages WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) PS C:\Users\Administrator\Desktop> python -m pip uninstall -r requirements.txt -y Found existing installation: absl-py 2.3.1 Uninstalling absl-py-2.3.1: Successfully uninstalled absl-py-2.3.1 Found existing installation: accelerate 0.21.0 Uninstalling accelerate-0.21.0: Successfully uninstalled accelerate-0.21.0 Found existing installation: addict 2.4.0 Uninstalling addict-2.4.0: Successfully uninstalled addict-2.4.0 Found existing installation: aiofiles 23.2.1 Uninstalling aiofiles-23.2.1: Successfully uninstalled aiofiles-23.2.1 Found existing installation: altair 5.5.0 Uninstalling altair-5.5.0: Successfully uninstalled altair-5.5.0 Found existing installation: annotated-types 0.7.0 Uninstalling annotated-types-0.7.0: Successfully uninstalled annotated-types-0.7.0 Found existing installation: anyio 4.9.0 Uninstalling anyio-4.9.0: Successfully uninstalled anyio-4.9.0 Found existing installation: attrs 25.3.0 Uninstalling attrs-25.3.0: Successfully uninstalled attrs-25.3.0 Found existing installation: basicsr 1.4.2 Uninstalling basicsr-1.4.2: Successfully uninstalled basicsr-1.4.2 Found existing installation: bidict 0.23.1 Uninstalling bidict-0.23.1: Successfully uninstalled bidict-0.23.1 Found existing installation: blinker 1.9.0 Uninstalling blinker-1.9.0: Successfully uninstalled blinker-1.9.0 Found existing installation: Brotli 1.1.0 Uninstalling Brotli-1.1.0: Successfully uninstalled Brotli-1.1.0 Found existing installation: certifi 2025.8.3 Uninstalling certifi-2025.8.3: Successfully uninstalled certifi-2025.8.3 Found existing installation: cffi 1.17.1 Uninstalling cffi-1.17.1: Successfully uninstalled cffi-1.17.1 Found existing installation: chardet 4.0.0 Uninstalling chardet-4.0.0: Successfully uninstalled chardet-4.0.0 Found existing installation: charset-normalizer 3.4.3 Uninstalling charset-normalizer-3.4.3: Successfully uninstalled charset-normalizer-3.4.3 Found existing installation: click 8.2.1 Uninstalling click-8.2.1: Successfully uninstalled click-8.2.1 Found existing installation: colorama 0.4.6 Uninstalling colorama-0.4.6: Successfully uninstalled colorama-0.4.6 Found existing installation: contourpy 1.3.2 Uninstalling contourpy-1.3.2: Successfully uninstalled contourpy-1.3.2 Found existing installation: cryptography 41.0.2 Uninstalling cryptography-41.0.2: Successfully uninstalled cryptography-41.0.2 Found existing installation: cycler 0.12.1 Uninstalling cycler-0.12.1: Successfully uninstalled cycler-0.12.1 Found existing installation: Deprecated 1.2.18 Uninstalling Deprecated-1.2.18: Successfully uninstalled Deprecated-1.2.18 Found existing installation: diffusers 0.19.3 Uninstalling diffusers-0.19.3: Successfully uninstalled diffusers-0.19.3 Found existing installation: diskcache 5.6.3 Uninstalling diskcache-5.6.3: Successfully uninstalled diskcache-5.6.3 Found existing installation: dnspython 2.7.0 Uninstalling dnspython-2.7.0: Successfully uninstalled dnspython-2.7.0 Found existing installation: einops 0.8.1 Uninstalling einops-0.8.1: Successfully uninstalled einops-0.8.1 Found existing installation: eventlet 0.40.2 Uninstalling eventlet-0.40.2: Successfully uninstalled eventlet-0.40.2 Found existing installation: exceptiongroup 1.3.0 Uninstalling exceptiongroup-1.3.0: Successfully uninstalled exceptiongroup-1.3.0 Found existing installation: fastapi 0.116.1 Uninstalling fastapi-0.116.1: Successfully uninstalled fastapi-0.116.1 Found existing installation: ffmpy 0.6.1 Uninstalling ffmpy-0.6.1: Successfully uninstalled ffmpy-0.6.1 WARNING: No metadata found in e:\python310\lib\site-packages Found existing installation: filelock 3.18.0 error: uninstall-no-record-file × Cannot uninstall filelock 3.18.0 ╰─> The package's contents are unknown: no RECORD file was found for filelock. hint: You might be able to recover from this via: pip install --force-reinstall --no-deps filelock==3.18.0 PS C:\Users\Administrator\Desktop> python -m pip install -r requirements.txt WARNING: Ignoring invalid distribution -odelscope (e:\python310\lib\site-packages) Processing e:\ai_temp\basicsr-1.4.2 (from -r requirements.txt (line 9)) ERROR: basicsr@ file:///E:/ai_temp/BasicSR-1.4.2 from file:///E:/ai_temp/BasicSR-1.4.2 (from -r requirements.txt (line 9)) does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found. PS C:\Users\Administrator\Desktop> # 将项目根目录添加到 Python 路径 PS C:\Users\Administrator\Desktop> $env:PYTHONPATH = "E:\AI_System" PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 然后尝试运行服务器 PS C:\Users\Administrator\Desktop> python server.py E:\Python310\python.exe: can't open file 'C:\\Users\\Administrator\\Desktop\\server.py': [Errno 2] No such file or directory PS C:\Users\Administrator\Desktop> # 创建虚拟环境 PS C:\Users\Administrator\Desktop> python -m venv venv PS C:\Users\Administrator\Desktop> PS C:\Users\Administrator\Desktop> # 激活虚拟环境 PS C:\Users\Administrator\Desktop> .\venv\Scripts\activate.ps1 (venv) PS C:\Users\Administrator\Desktop> (venv) PS C:\Users\Administrator\Desktop> # 在虚拟环境中安装依赖 (venv) PS C:\Users\Administrator\Desktop> pip install flask transformers torch numpy pandas scikit-learn Collecting flask Downloading flask-3.1.2-py3-none-any.whl (103 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 103.3/103.3 kB 10.2 kB/s eta 0:00:00 Collecting transformers Downloading transformers-4.55.3-py3-none-any.whl (11.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.3/11.3 MB 12.0 kB/s eta 0:00:00 WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/torch/ Collecting torch Downloading torch-2.8.0-cp310-cp310-win_amd64.whl (241.4 MB) ━━━━━╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 34.8/241.4 MB 16.8 kB/s eta 3:25:30
最新发布
08-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值