0x1 背景
为了在虚拟环境下开发AI工具,项目经理给我们一个项目启动环境的安装guide,总共10步非常简单, 其中有几步如下, 计划10步总消耗Effort:0.5H
§ curl -sSL https://install.python-poetry.org | python -
§ cd ./ProjectDir/Lib/
§ poetry install
§ poetry shell
注:我觉得这个这个时间需要半天到一天,哈哈,可惜没有具体理由,只是个直觉。就默认开干。
0x2 问题及尝试
0x20 powershell下curl命令失败
启动powershell终端(vscode 默认启动的就是powershell). 结果直接就失败:
PS C:\Workspace\AIProject> curl -sSL https://install.python-poetry.org| python -
Invoke-WebRequest : A parameter cannot be found that matches parameter name 'sSL'.
At line:1 char:6
+ curl -sSL https://install.python-poetry.org| python -
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
非常奇怪 怎么会调到invoke-webRequest呢?太迷惑了,只能helo以下copilot协助一下,结果如下:
question | #terminalSelection what's problem? |
answer | The error message you're seeing indicates that PowerShell is interpreting `--version` as a URL, which is incorrect. This is because `curl` in PowerShell is an alias for `Invoke-WebRequest`, and it doesn't support the same arguments as the traditional `curl` command found in Unix-like systems. To check the version of `curl` in PowerShell, you need to use the actual `curl.exe` command. Here's how you can do it: ```powershell This command tells PowerShell to use the actual `curl` executable (if it's installed and in your system's PATH), not the `curl` alias. |
原来 powershell中的curl不是我们理解的curl,是一个别名
PS C:\Workspace\AIProject> Get-Alias curl CommandType Name Version Source |
至此,我有种预感,后面可能还会又坑,果断切换到git-bash进行安装。
0x21 git-bash下curl 指令安装poetry失败
由于提供的指令是git-bash, 为了避免不必要的错误,就安装了最新版本的git-bash. 执行 § curl -sSL https://install.python-poetry.org | python - 顺利完成安装, 结果如下图所示 (git-bash 终端):
结果发生错误,无法安装1.8.3版本,查看log,原来是没有1.8.3的版本 存在:
结果不存在 1.8.3版本 |
ERROR: Could not find a version that satisfies the requirement poetry==1.8.3 (from versions: 0.1.0,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1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.1.6, 1.1.7, 1.1.8, 1.1.9, 1.1.10, 1.1.11, 1.1.12, 1.1.13, 1.1.14, 1.1.15, 1.2.0a1, 1.2.0a2) Traceback: File "<stdin>", line 923, in main |
考虑到同事能够安装,那么问题一定在自己身上;检查自己的python 版本是3.6.8 再去官网看看,已经到13了,不管三七二十一,先换python版本,就换成12吧, 更换后,果然成功执行该条命令, 如下图所示(这个是我后来补的,仅供参考)
marek@PC-52520 MINGW64 /c/Workspace/AIProject/aitool (master) $ curl -sSL https://install.python-poetry.org | python - Retrieving Poetry metadata # Welcome to Poetry! This will download and install the latest version of Poetry, a dependency and package manager for Python. It will add the `poetry` command to Poetry's bin directory, located at: C:\Users\marek\AppData\Roaming\Python\Scripts You can uninstall at any time by executing this script with the --uninstall option, and these changes will be reverted. Installing Poetry (1.8.3): Done Poetry (1.8.3) is installed now. Great! You can test that everything is set up by executing: `poetry --version` |
0x23 poetry shell指令失败
继续执行后面的命令,结果发现又出现如下错误:要求python版本在3.8.1和3.12之间,且不包括3.12和3.9.7 真是晕😵(猜中了,但是不够精准啊,哈哈)
继续换3.11版本。安装完后,为了不产生版本 间的干扰,顺便把3.6 /3.12的都 uninstall掉。
继续运行 poetry shell, 结果算是捅了马蜂窝了,以下是我部分的尝试方式截图,请参考:
marek@PC-52520 MINGW64 ~ $ poetrt env info bash: poetrt: command not found marek@PC-52520 MINGW64 ~ $ poetrt env use /c/Software/Python311/python.exe No Python at '"C:\Software\Python312\python.exe' marek@PC-52520 MINGW64 ~ $ poetry config cache-dir No Python at '"C:\Software\Python312\python.exe' marek@PC-52520 MINGW64 ~ $ poetry env remove python No Python at '"C:\Software\Python312\python.exe' |
总之,关于poetry的不管什么命令,都提示No Python at '"C:\Software\Python312\python.exe' 像是着了魔。 |
实在是没法弄了,就卸载, 并重新安装:
marek@PC-52520 MINGW64 $ curl -sSL https://install.python-poetry.org | python - --uninstall Removing Poetry (1.8.3) |
marek@PC-52520 MINGW64 $ curl -sSL https://install.python-poetry.org | python - Retrieving Poetry metadata # Welcome to Poetry! This will download and install the latest version of Poetry, a dependency and package manager for Python. It will add the `poetry` command to Poetry's bin directory, located at: C:\Users\marek\AppData\Roaming\Python\Scripts You can uninstall at any time by executing this script with the --uninstall option, and these changes will be reverted. Installing Poetry (1.8.3): Done Poetry (1.8.3) is installed now. Great! You can test that everything is set up by executing: `poetry --version` |
0x3 问题解决
简单来讲,就是卸载poetry 然后再安装。
curl -sSL https://install.python-poetry.org | python - --uninstall
curl -sSL https://install.python-poetry.org | python
0x4 一点感想
一个好的guide 应该包括:前置条件,操作过程,后置条件,注意事项等。这样会避免更多坑,而且使我们的工作更顺利。比如老板的这个guide,如果定义了前置条件:git-bash最新版,phthon用3.8以上,3.12一下,且不能是3.9。不能在powershell下操作 等等。那就会好很多。后置条件也应该有,如果正确安装成功,通常要做那些操作验证成功,以及异常情况有哪些,避免那些误操作等。