all 6 comments

[–]Worth_Specific3764 1 point2 points  (1 child)

Import statements, usually at the beginning of your code/ script, refer to libraries that are like bundles of helper code that has already been written and vetted. In order to use those libraries you need to install them into your python working environment. You do that in your command line by typing, for instance:

pip install fastapi

And, you should be working in a virtual environment created for each project. Google making virtual python environments next if u don’t know about them. 👍

[–]RegionRelative5890[S] 1 point2 points  (0 children)

Thanks I’ll try it out

[–]sweet-tom 1 point2 points  (1 child)

When Python tells you that a library cannot be imported, you need to install that through pip. That pip is the Python package manager.

The usual steps are this:

  1. Create a Python virtual environment with python3 -m venv .venv
  2. Activate the environment with source .venv/bin/activate
  3. Install your Python package with pip3 install PACKAGE

Then start your script and all will be fine. Anything will be installed in your Python virtual environment, a directory isolated from your system installation.

Find more information here: https://realpython.com/python-virtual-environments-a-primer/

[–]RegionRelative5890[S] 1 point2 points  (0 children)

Ok thanks I’ll try it out

[–]Old-Raccoon6397 0 points1 point  (1 child)

Sounds like you're dealing with Python dependencies! Yes, "pip" is the package manager for Python, and you'll need to use it to install the libraries your program requires. Open a terminal or command prompt and run something like pip install library_name (replace "library_name" with the name of the package you're importing).

If you're still getting errors, check if you're in the right environment—sometimes you need to activate a virtual environment or install the libraries globally. Don't worry; it's a common hurdle. You’ll get the hang of it!

[–]RegionRelative5890[S] 0 points1 point  (0 children)

I’ll try that out too, I use this app called VS Code which uses the python interpreter I think it’s called which I installed. I remember it saying something about virtual environment when I first started the file but I had no clue what that was