Home > Net >  import "modulexxx" could not be resolved - Visual Studio - Python
import "modulexxx" could not be resolved - Visual Studio - Python

Time:07-29

I'm new with python (3.x). I'm tryng to import a module into my code, but I get de error "import 'modulexxxx' could not be resolved"

how can I fixed?. I'm working with visual studio. Below image of how I am trying

enter image description here

CodePudding user response:

I think you need to put them all in the same folder. At the moment, your funcionesMathematicas file is in a subfolder. So bring it into the same directory and that should solve your problem.

You can find more information on importing modules, and, for example, how to access them in different directories if you do a quick Google search or just elsewhere on this website.

P.S. please mark the answers that respond to you as th solution if you like them (for example on your other post), it helps out!

CodePudding user response:

You can import python modules in multiple ways. To import a module like you've done

import funcionesMatematics

It is required that the module exists in the same folder as Pruebas.py.

However, you can use relative imports if it's required that the module be in a different folder. For example if your directory structure looked like this,

src
 - modules
  - funcionesMatemtics.py
 - pruebas.py

You could import using:

from modules import funcionesMatemtics

Or, if your directory structure looked like this:

src
 - modules
  - functionMatemtics.py
 - scripts
  - pruebas.py

You could import using:

from ..modules import functionMatemtics

If using the last method, make sure to run pruebas.py as a package, i.e

python3 -m src.scripts.pruebas.

There is more information on the python documentation (https://docs.python.org/3/reference/import.html) Hope this helps!

  • Related