简体   繁体   English

可嵌入 Python - 项目文件夹的 ModuleNotFoundError

[英]Embeddable Python - ModuleNotFoundError for project folders

I'm trying to create an embedded python for my project.我正在尝试为我的项目创建一个嵌入式 python。

  1. I downloaded the portable python 3.7.6我下载了便携式 python 3.7.6
  2. Copied the folders from my main python installation (Lib, Scripts, include, DLLs etc..)从我的主要 python 安装(Lib、脚本、包含、DLL 等)复制文件夹
  3. Added them to the PTH file like so:像这样将它们添加到 PTH 文件中:

     python37.zip. Lib Lib/site-packages Scripts include DLLs doc libs Tools tcl # Uncomment to run site.main() automatically #import site

and when I tested it, I tried to run a project with the following structure:当我测试它时,我尝试运行具有以下结构的项目:

文件夹结构

By running the command (using the embedded python): G:\GitHub\VRoscopy\VRoscopy\Conversion\python\python.exe main.py通过运行命令(使用嵌入式 python):G:\GitHub\VRoscope\VRoscope\Conversion\python\python.exe main.py

I get the following error:我收到以下错误:

> Traceback (most recent call last):   
>   File "mymain.py", line 1, in <module>
>     import folder.module as m ModuleNotFoundError: No module named 'folder'

However, when I try running the system python everything works normally.但是,当我尝试运行系统 python 时,一切正常。

Hope anyone can help me, thanks希望有人能帮助我,谢谢

The problem was solved by adding the project files to the PTH file, and uncommenting the "import site" like follows:通过将项目文件添加到 PTH 文件并取消注释“导入站点”,问题已解决,如下所示:

python37.zip . ../invesalius
../invesalius/*  # <----- added this line
Lib 
Lib/site-packages
Scripts
include
DLLs
doc
libs
Tools
tcl
# Uncomment to run site.main() automatically 
import site

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM