Import "spacy" could not be resolved Pylance (reportMissingImports)
Asked Answered
T

3

6

I am new to python and I don't have much experience in constructing a good working directory. But in my past experience working with installed packages through pip, I don't have any issues.

I am trying to download, install and import spacy. According to my pip list, I see the spacy package is successfully downloaded. But when I try to create a python document on MS visual studio code, running the code import spacy in my terminal, it says

Import "spacy" could not be resolved Pylance (reportMissingImports).

When I run it on command, it says:

2021-07-10 15:41:04.164329: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2021-07-10 15:41:04.164530: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
INFO:tensorflow:Enabling eager execution
INFO:tensorflow:Enabling v2 tensorshape
INFO:tensorflow:Enabling resource variables
INFO:tensorflow:Enabling tensor equality
INFO:tensorflow:Enabling control flow v2

I wonder if anyone is having a clue on what is going on.

Tuberose answered 10/7, 2021 at 14:42 Comment(1)
Did you notice this remark in the log: Ignore above cudart dlerror if you do not have a GPU set up on your machine? The message could not be resolved is a technical shortcoming of the linter and happens quite frequently when a library module is written in C/C++ and there is no Python implementation to check your code against.Placate
D
4

You can simply create a requirements.txt file where all your installs are listed. Every time you add something, update the requirements file by running pip freeze > requirements.txt and then when you activate your virtual environment, you can just run py -m pip install -r requirements.txt to fix similar issues with missing imports, etc...

Disprize answered 7/2, 2022 at 8:33 Comment(0)
T
3

I managed to solved this question by setting up a virtual environment in the directory I'm working on, installing the packages I needed for the project.

Tuberose answered 11/7, 2021 at 20:10 Comment(0)
D
0

Debug:

Terminal

  1. Create a virtual environment:
python -m venv .env
  1. Activate the virtual environment:
source .env/bin/activate  # Unix/Linux/Mac
.env\Scripts\activate.bat  # Windows
  1. or, activate conda (if not already activated):
conda create -n venv
conda activate venv
  1. Install the spacy-llm package using conda:
conda install spacy-llm
  1. Validate installation
python -m spacy validate

In VScode:

  • cmd + p

  • > Python: Select interpreter + return

  • select interpreter at workspace level: venv env python 3.11.3 virtual environment

References:

Denbrook answered 15/5, 2023 at 4:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.