0

I can´t import any module in VSCode.

The structure of my project is the next: 6.Python -.vscode -settings.json -Ortiz -init.py -puntoentrada.py -Paquetes -Prueba1 -init.py -prob.py

puntoentrada.py looks like this: puntoentrada.py

Then, this is prob.py I tried to run this but I have a problem called: ModuleNotFoundError: No module named 'puntoentrada' prob.py

Then, this is the directory of Python Directory

Then, this is the variable environment PythonPath

Then, this is my Python > Analysis Cache Folder Path in VSCode: Configure VSCode This is the same in "Usuario", "Area de trabajo" and "6.Python"

Then, this is my settings.json settings.json

I only want to execute "prob.py" and the only task is "import puntoentrada", but I cant do it, because puntoentrada according to VSCode "does not exist"

So, what can I do?

  • 2
    According to the [mre] page, "`DO NOT use images of code`". Your example should only be the minimal amount of code required to reproduce the issue. – Random Davis Sep 17 '20 at 15:08

2 Answers2

0

This is not a VSCode, but a Python issue. Python looks in serveral places for packages and modules and you can inspect these places via the sys.path. If prob.py is your main script, Python finds all modules that are in the same folder as prob.py. If your script is in a subfolder, you have to tell that to Python:

from subfolder import mymodule

If the module is part of a package in a completely separate path, your best option is to install that package in editable mode:

pip install path/to/mypackage -e

But you have to have a setup.py in that second package.

A quick-and-dirty workaround would be to simply add that separate path to sys.path using the append method.

Peter
  • 10,959
  • 2
  • 30
  • 47
0

I have changed my Python version for the operating environment in these places.

On the top right corner, you can choose the Python Version. enter image description here

enter image description here

On the left bottom corner, you can choose the Python version.

James Huang
  • 63
  • 1
  • 10