我正在运行WSL:通过VSCODE运行ubuntu。在终端中,我有一个虚拟环境.venv,已激活。 background

问题描述 投票:0回答:0
文件是结构化的,使电子应用在父文件夹中,并且该文件夹中的文件夹是一个称为“ PY”的文件夹,该文件夹包含烧瓶应用程序和“ .venv”文件夹的所有文件。为了简单起见,所有指向“ .venv”文件夹及其子女的路线都将缩短为“ [...]/py/.venv/

问题

这发生在我通过the端子运行电子应用程序时,烧瓶应用也会运行。当我这样做时,会出现以下错误:

npm start

我跑了
stderr:     from jsonschema import validate
ModuleNotFoundError: No module named 'jsonschema'
,发现“ jsonschema”确实是

努力解决

i怀疑这是通过安装错误并将以下行添加到我的烧瓶应用程序并独立运行以下行引起的一些错误:

pip freeze > requirements.txt
this this Prints:

import sys print("Executing in", sys.executable) if "jsonschema" in sys.modules: print("JSONSchema is in the modules") else: print("jsonschema isn't in the modules")

检查解释器,它将选定的解释器作为“ [...]/py/.venv/.venv/bin/python3.10”,所以我将其更改为Python3并重新启动VSCODE。我再次激活了虚拟环境,并独立运行了烧瓶应用程序,该应用程序仍然指向Python3,然后运行了电子应用程序,该应用程序仍然出现了错误。我再次检查了解释器,发现所选解释器是“ [...]/py/.venv/bin/python3”,工作区的解释器仍然是“ [...]/py/.venv/.venv/bin/python3 .10“

Image of virtual environment's requirements

当我尝试运行

Executing in [...]/py/.venv/bin/python3 JSONSchema is in the modules

pip install jsonschema
时,我收到了以下消息:

python -m pip install jsonschema

说他们正在安装到Python3.10中。当使用哪个位置为“ [...]/py/.venv/lib/python3.10/site-ackages”时,这将证实这一点。 Selected InterpreterEdit:

wrumningRequirement already satisfied: jsonschema in ./py/.venv/lib/python3.10/site-packages (3.2.0) Requirement already satisfied: six>=1.11.0 in ./py/.venv/lib/python3.10/site-packages (from jsonschema) (1.17.0) Requirement already satisfied: attrs>=17.4.0 in ./py/.venv/lib/python3.10/site-packages (from jsonschema) (25.1.0) Requirement already satisfied: setuptools in ./py/.venv/lib/python3.10/site-packages (from jsonschema) (59.6.0) Requirement already satisfied: pyrsistent>=0.14.0 in ./py/.venv/lib/python3.10/site-packages (from jsonschema) (0.20.0) Workspace Interpreter给出:

python -m pip show jsonschema

表明 /python和/python3.10都指向“ python3”,而 /python3指向“ /usr /bin /python3”。我认为这意味着Python3.10是Python3的一个分支,因此问题在于,在Python3中运行的“ doutes.py”文件无法从Python3.10导入JSonschema,因为它是上游的?考虑到这一点,我尝试运行:
ls -la py/.venv/bin/python*
专门将模块安装到Python3中,但与以前相同的“需求已经满足”的消息,使我更加困惑。
在评论中,我尝试通过电子应用程序运行
lrwxrwxrwx 1 <username> <username> 7 Feb 18 11:46 py/.venv/bin/python -> python3 lrwxrwxrwx 1 <username> <username> 16 Feb 18 11:46 py/.venv/bin/python3 -> /usr/bin/python3 lrwxrwxrwx 1 <username> <username> 7 Feb 18 11:46 py/.venv/bin/python3.10 -> python3

线,该线路给出了:
py/.venv/bin/python3 -m pip install jsonschema

这就是实际问题:
出于某种原因,通过电子应用程序运行到与独立运行时,Blask应用程序正在执行其他解释器。

是默认的Python解释器的路线,所以我在下面更改了它工作空间的范围指向“ [...]/py/.venv/bin/python3”,就像烧瓶Sys.ss.ss.scutable,但没有任何更改。 看着设置,它指出:

print("Executing in",sys.executable)

因此,我也尝试更改远程和用户默认的解释器路径,但这一无所有。
为什么电子应用不在正确的解释器上运行?为什么专门运行?我该如何更改它以在“ [...]/py/.venv/bin/python3”上运行

因此,问题在于我如何在main.js文件中产生flaskproc。我正在使用

Executing in C:\Python312\python.exe jsonschema isn't in the modules

,只是以为PY被用来表明它是运行Python代码,但是,默认情况下似乎在
C:\Python312\python.exe

上运行该代码。

I发现我可以将Spawn设置为“ WSL”,以告诉Node运行WSL命令。然后,我将通往虚拟环境和脚本作为参数的路径传递,因此它将两者都运行,从而允许脚本在WSL虚拟环境中运行。最终看起来像这样:

The setting has also been modified in the following scopes:

- Remote
- User

,这是完整的连接功能,以防将来帮助某人,尽管我觉得这篇文章应该表明我绝不是对此的权威,大声笑:

C\Python312\python.exe 感谢您对所有帮助的人!

    

python electron
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.