-1

I am trying to use pyperclip for a python course I am doing and it tells me to import pyperclip, but when I import it VS code says Import "pyperclip" could not be resolved even though I went into the terminal and installed it my python version is 3.10.6 64bit does anyone know how to fix this?

pip install pyperclip
muzeD1
  • 11
  • 3
  • have you tried running a python file with import pyperclip? and see whether it stops at the import? – Anonymous Aug 08 '22 at 15:46
  • Are you familiar with virtual environments? https://code.visualstudio.com/docs/python/environments. Did you install pyperclip in the virtual environment, you are using in VS Code? – svebert Aug 08 '22 at 15:47
  • I ran another code that has import pyperclip and it will stop and give me the errors saying import could not be resolved – muzeD1 Aug 08 '22 at 15:51
  • Okay, but does it work when run from the terminal, the same place you installed pyperclip? If so, pyperclip is installed in that Python environment, but not in whatever environment VSCode is using. – CrazyChucky Aug 09 '22 at 01:59

1 Answers1

2

Follow the steps below to choose an interpreter

  1. Open the command palette with Ctrl+Shift+P
  2. Search for Python:Select Interpreter
  3. Choose the correct interpreter

It is recommended to use a virtual environment

use the following command in the vscode terminal:

  • Create a virtual environment ( named .venv )

    python -m venv .venv
    
  • Activate the virtual environment

    .venv/Scripts/Activate
    
  • Select the interpreter in the virtual environment

  • Create a new terminal to automatically activate the virtual environment

  • Install the packages you need to use in the current environment

Virtual environments can help you manage using different python versions and using different packages.

JialeDu
  • 6,021
  • 2
  • 5
  • 24