简体   繁体   中英

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.

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.

The problem appears when I try to use the class from other package using the syntax form clases.NotaParcial import *

I have tried already put an __init__.py file in the package.

The error message is:

Exception has occurred: ModuleNotFoundError No module named '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)

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.

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.

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.

The problem appears when I try to use the class from other package using the syntax form clases.NotaParcial import *

I have tried already put an __init__.py file in the package.

The error message is:

Exception has occurred: ModuleNotFoundError No module named '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)

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.

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.

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.

The problem appears when I try to use the class from other package using the syntax form clases.NotaParcial import *

I have tried already put an __init__.py file in the package.

The error message is:

Exception has occurred: ModuleNotFoundError No module named '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)

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.

For me the PYTHONPATH was key to the solution, see answer here:

How to correctly set PYTHONPATH for Visual Studio Code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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