Creating a virtual environment is good practice anyway for Python development in general, as it helps to manage dependencies and avoid conflicts.

Create virtual environment

Use the Command Palette (CTRL+SHIFT+P) to open a new terminal session with “Terminal: Create New Terminal”.

Then create a new virtual environment by running the following commands in the terminal:

python -m venv .venv –system-site-packages
source .venv/bin/activate
python -m pip install –upgrade pip setuptools wheel

VSCode will ask “We noticed a new environment has been created. Do you want to select it for the workspace folder”
Click “Yes”

The “–system-site-packages” is an optional argument which means that the virtual environment will also have access to the system site-packages dir (see here)

The virtual environment will be created in a folder called “.venv” (you don’t need to put your project files in it).

GitHub

Make sure to update your ‘gitignore to prevent committing your virtual environment.

Selecting the environment to be used

Use the Command Palette (CTRL+SHIFT+P) Python: Select Interpreter
Select the “.venv” one

Install a package

Ensure pip is up to date:

python.exe -m pip install --upgrade pip

In the terminal window just use a normal pip install command, e.g.:

pip3 install ultralytics

(It will get installed in \.venv.Lib\site-packages)

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *