---
title: "运行时PyImport_ImportModule或者py::import调用失败， error_already_set"
author: "johnsmith9th"
date: "2023-03-24T20:29:49Z"
tags: []
categories: ["编程语言"]
slug: "pyimport-importmodule-py-import-error-already-set"
draft: false
lastmod: "2023-03-24T20:29:49Z"
id: 2539189
url: "https://johnsmith9th.iteye.com/blog/2539189"
---

解决方案1： 拷贝python或conda目录下的DLLs和Lib文件夹到exe文件所在目录

解决方案2： 提前调用Py\_SetPythonHome(你安装的python或conda的目录)

解决方案3： （思路可参考https://blog.csdn.net/liulina603/article/details/79442021）

```
  PyRun_SimpleString("import sys"); 
  PyRun_SimpleString("sys.path.append('第三方或你自己写的py文件所在目录')");
```