0

this is my first question and I searched the whole internet for one day and couldn't find a solution.
Hopefully someone can help me here.

I have running Anaconda and Python 3.8.3 64-bit on Windows 10.

I want to import an own program modul from an other file in an other folder .

  • foldera contains a testa.py file
  • folderb contains a testb.py file. I want to import foldera.testa

The import does not work. Terminal says ModuleNotFoundError: No module named

VS Code Screenshot

What I tryed:

  • put the file: __init__.py and .envin every project folder.
  • Reinstalling both programs and deleted temp files
  • Looking folder .vscode into settings.json showed that the python.pythonPath is set correctly to python.exe
  • Typed in python.exe sys.path.append('\\path\\to\\whatever') and os.environ['PYTHONPATH'] = '\\path\\to\\whatever'

Thank you in advance for the help

Best regards Sepp

  • 1
    Welcome to SO! Please NEVER post text (as in code, error messages etc.) as images. Read [this article](https://stackoverflow.com/help/how-to-ask) on how to ask good questions. A well asked question is way more likely to receive answers that actually help you. – toydarian Sep 02 '20 at 14:51
  • Does this answer your question? [How to set the root directory for Visual Studio Code Python Extension?](https://stackoverflow.com/questions/50089498/how-to-set-the-root-directory-for-visual-studio-code-python-extension) – toydarian Sep 02 '20 at 14:54
  • Can you please [edit] your question to clarify what you are asking about? The title and image show a different issue. – MisterMiyagi Sep 02 '20 at 14:55
  • As you are new, I'll explain a little more. My second comment means, that I flagged your question as duplicate, as I think it has been answered before. Please read this question and the answers carefully and try if this solves your problem. – toydarian Sep 02 '20 at 14:58
  • @toydarian i tried it and wondered because in the settings.json file the filepath are written different. pythonPath \, envFile / "python.pythonPath": "C:\\ProgramData\\Anaconda3\\python.exe", "python.envFile": "${workspaceFolder}/.env" – 0815_programmer Sep 02 '20 at 15:37
  • @toydarian sadly that hasn't worked for me. – 0815_programmer Sep 03 '20 at 06:38

1 Answers1

0

I create a project with the same folder structure as yours, like the following screenshot shows:

enter image description here

In launch.json, you should add

"cwd": "${workspaceFolder}",

when testb.py looks for the module, this setting makes it first to search in the current workspace folder, and the code sys.path.append("./") let it turn to its parent directory, now testb.py is at the same level as foldera, so you can use import foldera.testa without any errors.

Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22