【发布时间】:2022-11-27 23:29:51
【问题描述】:
问题描述: 我有一个涉及实时 python 脚本解释的 Visual Studio 2022 C++ 项目。当然,我需要一个有效的 Python 安装来执行此操作。但是,我打算将它作为一个应用程序发布,所以我想要一个本地化的 Python 安装,以避免消费者端安装,但这不会干扰 Windows 的环境变量。
我做了什么: 我从 Python 安装的“include”文件夹中包含“Python.h”,我已将其“libs”文件夹添加到“其他库目录”,我已将“python311.lib”添加到“其他依赖项”,我记得将 Python311.dll 复制到我项目的解决方案目录中。一切都正确链接。但是,当我运行编译并执行我的程序时,我收到一长串错误,如下所示:
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = 'python'
isolated = 0
environment = 1
user site = 1
safe_path = 0
import site = 1
is in build tree = 0
stdlib dir = 'C:\Coding Projects\MaSGE\Lib'
sys._base_executable = 'C:\\Coding Projects\\MaSGE\\x64\\Release\\MaSGE.exe'
sys.base_prefix = 'C:\\Coding Projects\\MaSGE'
sys.base_exec_prefix = 'C:\\Coding Projects\\MaSGE'
sys.platlibdir = 'DLLs'
sys.executable = 'C:\\Coding Projects\\MaSGE\\x64\\Release\\MaSGE.exe'
sys.prefix = 'C:\\Coding Projects\\MaSGE'
sys.exec_prefix = 'C:\\Coding Projects\\MaSGE'
sys.path = [
'C:\\Coding Projects\\MaSGE\\python311.zip',
'C:\\Coding Projects\\MaSGE\\Lib',
'C:\\Coding Projects\\MaSGE\\DLLs',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x0000399c (most recent call first):
<no Python frame>
我特别感兴趣的是前两行,加上第 4 行和第 5 行的“PYTHONHOME =(未设置)”和“PYTHONPATH =(未设置)”,据我所知,它们是环境变量。
这让我想到了问题的症结所在: 有什么方法可以将便携式 Python 解释器安装到特定文件夹以规避环境变量问题?
【问题讨论】:
-
这就是安装程序存在的原因。
-
这不是远程帮助。
标签: python c++ visual-studio-2022 python-install