RubyMetric / chsrc

chsrc 全平台通用换源工具. Change Source for every software on every platform from the command line.
https://gitee.com/RubyMetric/chsrc
GNU General Public License v3.0
1.32k stars 54 forks source link

在Windows上使用Microsoft Store安装的Python换源会遇到权限问题 #39

Closed DBinK closed 16 hours ago

DBinK commented 1 week ago

完整运行日志如下

PS C:\Users\用户名> sudo  ./chsrc set pip
[chsrc 检查] √ 命令 python3 存在
[chsrc 检查] x 命令 pdm 不存在
[chsrc 检查] √ 命令 curl 存在
测速 https://mirrors.bfsu.edu.cn/ ... 1.01 MByte/s
测速 https://mirror.lzu.edu.cn/ ... 24.91 MByte/s
测速 https://mirrors.jlu.edu.cn/ ... 7.86 MByte/s
测速 https://mirrors.sjtug.sjtu.edu.cn/ ... 12.78 MByte/s
测速 https://mirrors.tuna.tsinghua.edu.cn/ ... 2.04 MByte/s
测速 https://developer.aliyun.com/mirror/ ... 294.12 KByte/s
测速 https://mirrors.tencent.com/ ... 1.25 MByte/s
测速 https://mirrors.huaweicloud.com/ ... 7.35 MByte/s
测速 https://mirrors.hust.edu.cn/ ... 3.84 MByte/s
最快镜像站: 兰州大学开源社区镜像站
选中镜像站: LZUOSS (lzu)
--------------------------------
[chsrc 运行] python3 -m pip config set global.index-url https://mirror.lzu.edu.cn/pypi/web/simple
Writing to C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\pip.ini
ERROR: Unable to save configuration. Please report this as a bug.
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\site-packages\pip\_internal\configuration.py", line 215, in save
    with open(fname, "w") as f:
         ^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\\pip.ini'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\site-packages\pip\_internal\commands\configuration.py", line 265, in _save_configuration
    self.configuration.save()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\site-packages\pip\_internal\configuration.py", line 218, in save
    raise ConfigurationError(
pip._internal.exceptions.ConfigurationError: An error occurred while writing to the configuration file C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\pip.ini: [Errno 13] Permission denied: 'C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\\pip.ini'
ERROR: Internal Error.
[chsrc 运行] 命令执行失败,返回码 1
chsrc: 关键错误,强制结束

可能的解决方案: https://devv.ai/search?threadId=dpqkqovuws1s

ccmywish commented 1 week ago

Hi @DBinK

感谢你的反馈!

我测试了一下,不加选项的时候 config set 和加了 --user 选项的 config --user set,写到的是同一个位置。

所以这个解决方案可能并不奏效。

我的运行环境:

  1. 通过 scoop 安装
  2. python 3.12.4
  3. pip 24.0

不知道你那边用 --user 的情况如何?

DBinK commented 1 week ago

Hi @DBinK

感谢你的反馈!

我测试了一下,不加选项的时候 config set 和加了 --user 选项的 config --user set,写到的是同一个位置。

所以这个解决方案可能并不奏效。但是我是通过 scoop 安装测试的,不知道你那边的情况如何?

这个解决方案在我这里验证可行

我手动添加 --user 参数运行以下命令后

pip config set global.index-url https://mirror.lzu.edu.cn/pypi/web/simple

使用 pip config list 验证,可以看到 image

但似乎是 Python 这边有 bug

在我电脑上,它实际上修改了这个文件 C:\Users\用户名\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\Roaming\pip\pip.ini

文件内容是

[global]
index-url = https://mirror.lzu.edu.cn/pypi/web/simple

我使用 Everyting 搜索 pip.ini ,会找到这两个文件 image 另一个文件里的内容似乎就是系统级的配置,在上一张图片中 pip config list 的输出可以看到一摸一样的内容

ccmywish commented 1 week ago

这很奇怪,不知道是不是通过Micorsoft Store安装的 Python 被微软调整了配置的路径。

如果是这样的话,可能确实在你那边默认不加选项和加了 --user 是不一样的。

我已经在代码中给Python换源时默认添加了 --user,因为通过其他方式安装的 python,有无 --user 是一样的,不会影响其他用户,同时也能解决你的问题。


我暂时只修改了代码还没有发布,等过几天会发布chsrc v0.1.7,届时可下载试用。

ccmywish commented 4 days ago

@DBinK

我刚已发布了最新版,可以从README链接中下载试用,若无问题,可关闭此issue