question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import my own module could not be resolved

See original GitHub issue

Output of :CocCommand pyright.version:

[coc.nvim] coc-pyright 1.1.161 with Pyright 1.1.161

Output of :CocCommand workspace.showOutput Pyright:

Workspace: C:\Users\MyPC Using python from C:\Users\MyPC\AppData\Local\Programs\Python\Python39\python.EXE

[Warn  - 8:19:35 AM] Ignored rootPath C:\Users\MyPC of client "pyright"
[Info  - 8:19:35 AM] Pyright language server 1.1.161 starting
[Info  - 8:19:35 AM] Server root directory: C:\Users\MyPC\AppData\Local\coc\extensions\node_modules\coc-pyright\node_modules\pyright/dist/
[Info  - 8:19:35 AM] No pyproject.toml file found.
[Info  - 8:19:35 AM] Setting pythonPath for service "<default>": "C:\Users\MyPC\AppData\Local\Programs\Python\Python39\python.EXE"
[Warn  - 8:19:35 AM] stubPath typings is not a valid directory.
[Info  - 8:19:35 AM] Assuming Python version 3.9
[Info  - 8:19:35 AM] Assuming Python platform Windows
[Info  - 8:19:35 AM] Searching for source files
[Info  - 8:19:35 AM] No source files found.

Here is my python folder: image

However, when I import my module in the same directory: image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
fannheywardcommented, Aug 20, 2021

The language server, here is Pyright, needs the workspace root to work, coc will try to detect the root by some patterns like .git, pyproject.toml and b:coc_root_patterns, that’s why you need to open vim in your project root.

0reactions
smthomas-scicommented, Nov 2, 2022

In a slightly different issue, where I have pip installed my own module with pip install -e, the python environment finds it when it runs, but pyright fails on linting. This might have something to do with the fact that in site-packages it includes a redirect to the parent directory (not in the workspace dir, because it doesn’t have to be via a pip install). The solution, which enables the python program to run and pyright to find the module, is to create a symbolic link in the workspace folder with the same name as the module, and point it to the original location… Hopefully saves someone time.

Note: adding a pyrightconfig.json with extraPaths: [‘<path_to_module>’], does not work.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Import could not be resolved/could not be ... - Stack Overflow
Open the Command Palette ( Ctrl + Shift + P ), then select the Python: Select Interpreter. From the list, select the virtual...
Read more >
Import could not be resolved [Pylance] : r/vscode - Reddit
Try to Reload Window. If the error still exists, check if you install the module in your selected interpreter environment.
Read more >
ModuleNotFoundError: no module named Python Error [Fixed]
As I mentioned in the previous section, there are a couple of reasons a module may not be found. Here are some solutions....
Read more >
Traps for the Unwary in Python's Import System
modules at the end as you should so tests don't influence each other. To save time you put custom exception classes in foo.py...
Read more >
Documentation - Module Resolution - TypeScript
A relative import is resolved relative to the importing file and cannot resolve to an ambient module declaration. You should use relative imports...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found