简体   繁体   English

如何使用 Visual Studio Code 修复 python 中的 ModuleNotFoundError

[英]How to fix ModuleNotFoundError in python with Visual Studio Code

I'm developing a basic manager of students' degrees for learning Python, also I'm coding in VS Code and with python 3.7.3 enviroment.我正在开发一个用于学习 Python 的学生学位的基本管理器,我也在使用 VS Code 和 python 3.7.3 环境进行编码。

I have created a package named clases inside of which are __init__.py and NotaParcial.py files, inside NotaParcial.py is just one class named NotaParcial too.我创建了一个名为clases的类,其中包含__init__.pyNotaParcial.py文件,在NotaParcial.py中也只有一个名为NotaParcial的 class。

The problem appears when I try to use the class from other package using the syntax form clases.NotaParcial import *当我尝试使用其他 package 使用语法form clases.NotaParcial import *

I have tried already put an __init__.py file in the package.我已经尝试在 package 中放置一个__init__.py文件。

The error message is:错误信息是:

Exception has occurred: ModuleNotFoundError No module named 'clases'发生异常:ModuleNotFoundError 没有名为“clases”的模块
File "C:\Users\Usuario\OneDrive\Ingenieria\Semestre 3\Parcial 1\Modelamiento de software\Tareas\PySAcademico\prueba\prueba.py", line 1, in from clases.moduloNotaParcial import NotaParcial File "C:\Users\Usuario\AppData\Local\Programs\Python\Python37\Lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\Usuario\AppData\Local\Programs\Python\Python37\Lib\runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "C:\Users\Usuario\AppData\Local\Programs\Python\Python37\Lib\runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname)文件“C:\Users\Usuario\OneDrive\Ingenieria\Semestre 3\Parcial 1\Modelamiento de software\Tareas\PySAcademico\prueba\prueba.py”,第 1 行,从 clases.moduloNotaParcial 导入 NotaParcial 文件“C:\Users \Usuario\AppData\Local\Programs\Python\Python37\Lib\runpy.py”,第 85 行,在 _run_code exec(code, run_globals) 文件“C:\Users\Usuario\AppData\Local\Programs\Python\Python37\ Lib\runpy.py”,第 96 行,在 _run_module_code mod_name, mod_spec, pkg_name, script_name) 文件“C:\Users\Usuario\AppData\Local\Programs\Python\Python37\Lib\runpy.py”,第 263 行,在run_path pkg_name=pkg_name, script_name=fname)

I've tried to call the class from a file located in a superior path of the package and it works.我尝试从位于 package 的上级路径中的文件中调用 class 并且它可以工作。 I've tried use Visual Studio 2017 Community to repeat the process and in that IDE, it works and the problem doesn't appear.我尝试使用 Visual Studio 2017 Community 重复该过程,并且在该 IDE 中,它可以工作并且问题没有出现。

I'm developing a basic manager of students' degrees for learning Python, also I'm coding in VS Code and with python 3.7.3 enviroment.我正在开发用于学习Python的学生学位的基本经理,也正在VS Code和python 3.7.3环境中进行编码。

I have created a package named clases inside of which are __init__.py and NotaParcial.py files, inside NotaParcial.py is just one class named NotaParcial too.我创建了一个名为clases的程序包,其中有__init__.pyNotaParcial.py文件, NotaParcial.py也只有一个名为NotaParcial类。

The problem appears when I try to use the class from other package using the syntax form clases.NotaParcial import *当我尝试使用语法form clases.NotaParcial import *其他包中的类时,会出现问题form clases.NotaParcial import *

I have tried already put an __init__.py file in the package.我已经尝试将__init__.py文件放入包中。

The error message is:错误消息是:

Exception has occurred: ModuleNotFoundError No module named 'clases'发生了异常:ModuleNotFoundError没有名为“ clases”的模块
File "C:\\Users\\Usuario\\OneDrive\\Ingenieria\\Semestre 3\\Parcial 1\\Modelamiento de software\\Tareas\\PySAcademico\\prueba\\prueba.py", line 1, in from clases.moduloNotaParcial import NotaParcial File "C:\\Users\\Usuario\\AppData\\Local\\Programs\\Python\\Python37\\Lib\\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\\Users\\Usuario\\AppData\\Local\\Programs\\Python\\Python37\\Lib\\runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "C:\\Users\\Usuario\\AppData\\Local\\Programs\\Python\\Python37\\Lib\\runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname)文件“ C:\\ Users \\ Usuario \\ OneDrive \\ Ingenieria \\ Semestre 3 \\ Parcial 1 \\ Modelamiento de software \\ Tareas \\ PySAcademico \\ prueba \\ prueba.py”,行1,来自clases.moduloNotaParcial导入NotaParcial文件“ C:\\ Users” \\ Usuario \\ AppData \\ Local \\ Programs \\ Python \\ Python37 \\ Lib \\ runpy.py”,第85行,位于_run_code exec(code,run_globals)文件“ C:\\ Users \\ Usuario \\ AppData \\ Local \\ Programs \\ Python \\ Python37 \\ Lib \\ runpy.py”,第96行,在_run_module_code中,mod_name,mod_spec,pkg_name,script_name)文件“ C:\\ Users \\ Usuario \\ AppData \\ Local \\ Programs \\ Python \\ Python37 \\ Lib \\ runpy.py”,第263行,在run_path pkg_name = pkg_name,script_name = fname)

I've tried to call the class from a file located in a superior path of the package and it works.我试图从位于程序包上级路径中的文件中调用该类,并且它可以工作。 I've tried use Visual Studio 2017 Community to repeat the process and in that IDE, it works and the problem doesn't appear.我尝试使用Visual Studio 2017社区重复该过程,并且在该IDE中可以正常工作,并且不会出现问题。

I'm developing a basic manager of students' degrees for learning Python, also I'm coding in VS Code and with python 3.7.3 enviroment.我正在开发用于学习Python的学生学位的基本经理,也正在VS Code和python 3.7.3环境中进行编码。

I have created a package named clases inside of which are __init__.py and NotaParcial.py files, inside NotaParcial.py is just one class named NotaParcial too.我创建了一个名为clases的程序包,其中有__init__.pyNotaParcial.py文件, NotaParcial.py也只有一个名为NotaParcial类。

The problem appears when I try to use the class from other package using the syntax form clases.NotaParcial import *当我尝试使用语法form clases.NotaParcial import *其他包中的类时,会出现问题form clases.NotaParcial import *

I have tried already put an __init__.py file in the package.我已经尝试将__init__.py文件放入包中。

The error message is:错误消息是:

Exception has occurred: ModuleNotFoundError No module named 'clases'发生了异常:ModuleNotFoundError没有名为“ clases”的模块
File "C:\\Users\\Usuario\\OneDrive\\Ingenieria\\Semestre 3\\Parcial 1\\Modelamiento de software\\Tareas\\PySAcademico\\prueba\\prueba.py", line 1, in from clases.moduloNotaParcial import NotaParcial File "C:\\Users\\Usuario\\AppData\\Local\\Programs\\Python\\Python37\\Lib\\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\\Users\\Usuario\\AppData\\Local\\Programs\\Python\\Python37\\Lib\\runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "C:\\Users\\Usuario\\AppData\\Local\\Programs\\Python\\Python37\\Lib\\runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname)文件“ C:\\ Users \\ Usuario \\ OneDrive \\ Ingenieria \\ Semestre 3 \\ Parcial 1 \\ Modelamiento de software \\ Tareas \\ PySAcademico \\ prueba \\ prueba.py”,行1,来自clases.moduloNotaParcial导入NotaParcial文件“ C:\\ Users” \\ Usuario \\ AppData \\ Local \\ Programs \\ Python \\ Python37 \\ Lib \\ runpy.py”,第85行,位于_run_code exec(code,run_globals)文件“ C:\\ Users \\ Usuario \\ AppData \\ Local \\ Programs \\ Python \\ Python37 \\ Lib \\ runpy.py”,第96行,在_run_module_code中,mod_name,mod_spec,pkg_name,script_name)文件“ C:\\ Users \\ Usuario \\ AppData \\ Local \\ Programs \\ Python \\ Python37 \\ Lib \\ runpy.py”,第263行,在run_path pkg_name = pkg_name,script_name = fname)

I've tried to call the class from a file located in a superior path of the package and it works.我试图从位于程序包上级路径中的文件中调用该类,并且它可以工作。 I've tried use Visual Studio 2017 Community to repeat the process and in that IDE, it works and the problem doesn't appear.我尝试使用Visual Studio 2017社区重复该过程,并且在该IDE中可以正常工作,并且不会出现问题。

For me the PYTHONPATH was key to the solution, see answer here:对我来说,PYTHONPATH 是解决方案的关键,请在此处查看答案:

How to correctly set PYTHONPATH for Visual Studio Code 如何为 Visual Studio Code 正确设置 PYTHONPATH

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

相关问题 ModuleNotFoundError:没有名为“selenium”的模块。 如何从 Visual Studio Code 修复它? - ModuleNotFoundError: No module named 'selenium'. How to fix it from Visual Studio Code? ModuleNotFoundError:使用 Visual Studio Code 在 Python 中没有名为“PySide6”的模块 - ModuleNotFoundError: No module named 'PySide6' in Python using Visual Studio Code 如何修复 Python ModuleNotFoundError - How to fix Python ModuleNotFoundError Visual Studio Code 快速修复和 python - Visual Studio Code quick-fix & python ModuleNotFoundError:Visual Studio Code 中没有名为“pyperclip”的模块 - ModuleNotFoundError: No module named 'pyperclip' in Visual Studio Code Visual Studio Code 中 matplotlib 和 pandas 的 ModuleNotFoundError - ModuleNotFoundError for matplotlib and pandas in Visual Studio Code 诗歌问题 - Visual Studio 代码调试中的 ModuleNotFoundError - poetry woes - ModuleNotFoundError in visual studio code debugging 使用 Visual Studio Code 时出现 ModuleNotFoundError - ModuleNotFoundError when using Visual Studio Code moduleNotFoundError:没有在 Visual Studio 代码中命名的模块 - moduleNotFoundError: No module named in visual studio code Visual Studio Code ModuleNotFoundError:没有名为“_overlapped”的模块 - Visual Studio Code ModuleNotFoundError: No module named '_overlapped'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM