_winapi.CreateProcess....FileNotFoundError: [WinError 2] 系统找不到指定的文件

方法1:

参考:

hellowac.github.io/uv-zh-cn/ge...

juejin.cn/post/754908...

zhuanlan.zhihu.com/p/195019831...

具体过程如下:

运行环境:window10

执行代码

ini 复制代码
from fastmcp import Client
from fastmcp.client.transports import StdioTransport
import asyncio

transport = StdioTransport(
    command="uvx",
    args=["amap-mcp-server"],
    env={'AMAP_MAPS_API_KEY': 'xxx'}
)

client = Client(transport)


async def example():
    async with client:
        list = await client.list_tools()
        print(f"{list}")

if __name__ == "__main__":
    asyncio.run(example(),debug=True) #debug模式看日志

报错:

hp, ht, pid, tid = _winapi.CreateProcess(executable, args,

FileNotFoundError: WinError 2 系统找不到指定的文件

arduino 复制代码
 File "E:\xxx\miniconda3\Lib\subprocess.py", line 1554, in _execute_child
    |     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
    |                        ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
    |                              # no special security
    |                              ^^^^^^^^^^^^^^^^^^^^^
    |     ...<4 lines>...
    |                              cwd,
    |                              ^^^^
    |                              startupinfo)
    |                              ^^^^^^^^^^^^
    | FileNotFoundError: [WinError 2] 系统找不到指定的文件。
    

解决方法

安装uvx,并配置环境变量

1、配置uvx安装路径,添加到环境变量中,重启电脑使之生效。

ini 复制代码
安装路径:
UV_INSTALL_DIR = E:\Programs\uvx

2、安装uvx

powershell以管理员身份运行,执行如下命令:

arduino 复制代码
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

3、验证

css 复制代码
win+R

uvx --version

成功显示:uvx信息即成功

4、重启pycharm执行

正常运行

方法2:

找到当前虚拟环境下的Lib/subprocess.py的文件,修改这个模块中的in _execute_child函数的初始化函数 init函数中的shell = False 改成shell = True。

参考:

www.cnblogs.com/ZerlinM/p/1...

相关推荐
用户83562907805114 分钟前
如何使用 Python 将 PowerPoint 转换为 PDF 文档
后端·python
菜冻鱼14 分钟前
Python-pytorch-高级技巧
开发语言·人工智能·pytorch·python·深度学习·神经网络·聚类
lpfasd12316 分钟前
python webview打包版卡死、开发版正常
开发语言·python
用户83562907805125 分钟前
如何使用 Python 为 PowerPoint 幻灯片添加切换效果
后端·python
菜冻鱼33 分钟前
Python-pytorch-模型保存与加载
开发语言·人工智能·pytorch·python·深度学习·机器学习
亿牛云爬虫专家1 小时前
爬虫调度系统设计:用 Celery 实现按媒体权重动态调整的抓取频率控制
爬虫·python·隧道代理·舆情采集·媒体权重·频率控制·ip自动轮换
Code额2 小时前
Python 连接 DeepSeek API,OpenAI
开发语言·python·ai·ai编程
Suhan423 小时前
SQLAlchemy的两种查询query()查询、stmt=select()查询
数据库·python·sql·oracle
AAA@峥3 小时前
Python 基础开篇:认识 Python、版本选择、环境部署与首个 HelloWorld
开发语言·python
Metaphor6923 小时前
使用 Python 快速在 Word 文档中插入图片
python·word