1

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

1

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

Comments

0

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.