4

I feel like I'm asking a dumb question, but I've looked at multiple StackOverflow threads and articles online already but still haven't fixed my problem.

I'm trying to use the OpenAI Python library to train a new model, but even after running multiple variations of the pip install openai command, VS Code and Powershell keep returning this:

Import "openai" could not be resolvedPylancereportMissingImports

and

PS C:\Users\achar\OneDrive\Documents\GitHub\TaxGPT> openai --version
openai: The term 'openai' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Here are some of the commands I've already tried:

  • pip install openai
  • pip install openai --user
  • pip install --upgrade pip
  • pip install --upgrade pip
  • pip3 install --upgrade openai --user
  • pip3 install --upgrade --force-reinstall openai --user

Thanks for your help, I really do appreciate it!

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36

4 Answers4

3

Have you set the Python PATH?

In command terminal, run:

where python

to return the location where python is installed.

In VSCode, open settings.json, which can be quickly accessed using command palette (CTRL + SHIFT + P) and typing settings.json. Choose the Preferences: Open User Settings (JSON).

Copy the path returned in the terminal.

In the file, add the line:

"python.defaultInterpreterPath": <THE PATH YOU COPIED>,

If the path you copied contains backslash, replace them with double backslash or single forward slash.

For example,

"python.defaultInterpreterPath": "C:\\Users\\<YOURUSERNAME>\\AppData\\Local\\Programs\\Python\\Python311\\python.exe",

I highly recommend reading the documentation in VSCode for Python: https://code.visualstudio.com/docs/python/settings-reference

Blooming
  • 43
  • 1
  • 8
2

Try this. It worked for me

py -m pip install openai --upgrade
toyota Supra
  • 3,181
  • 4
  • 15
  • 19
0

Thanks everyone for the tips! I actually had to re-install Python again from https://www.python.org/downloads/, which may have something to do with it not getting added to the PATH correctly.

0

To use these steps into the terminal in vs code and solve this problem.

  • python -m venv venv

  • .\venv\Scripts\activate

  • pip install openai

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 26 '23 at 12:04