Monday, October 5, 2026

How to remove and add .venv and requirements.txt in vs code

 

1. Open your project in VS Code

For example:

cd D:\vscode_python_practice

Check your current environment:

python --version

and:

python -c "import sys; print(sys.executable)"

2. Deactivate the current virtual environment

If you see:

(.venv) PS D:\vscode_python_practice>

run:

deactivate

The prompt should become:

PS D:\vscode_python_practice>

Verify:

python --version

3. Create requirements.txt from the existing environment

Do this before deleting .venv if you want to preserve your currently installed packages.

If the old .venv is still available, activate it again temporarily:

.\.venv\Scripts\Activate.ps1

Then:

pip freeze > requirements.txt

Example requirements.txt:

numpy==2.x.x
pandas==2.x.x
matplotlib==3.x.x
pyspark==4.x.x

Then deactivate:

deactivate

4. Delete the old .venv

From your project directory:

Remove-Item -Recurse -Force .venv

Check that .venv is gone:

Get-ChildItem

You should still have:

D:\vscode_python_practice
│
├── requirements.txt
├── your_python_files.py
└── ...

5. Install UV

First check whether UV is already installed:

uv --version

If it says that uv is not recognized, install UV.

One common Windows installation method is:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Close and reopen the VS Code terminal afterward.

Verify:

uv --version

You should get something similar to:

uv 0.x.x

6. Check whether Python 3.15 is available

Run:

uv python list

Look for:

cpython-3.15...

You can also ask UV to install Python 3.15:

uv python install 3.15

Then verify:

uv python list

7. Create a UV environment using Python 3.15

From:

D:\vscode_python_practice

run:

uv venv --python 3.15

This creates:

D:\vscode_python_practice\.venv

using Python 3.15.

You should see something similar to:

Using CPython 3.15...
Creating virtual environment at: .venv

8. Activate the UV environment

On Windows PowerShell:

.\.venv\Scripts\Activate.ps1

Your prompt should now show:

(.venv) PS D:\vscode_python_practice>

9. Verify Python 3.15

Run:

python --version

Expected:

Python 3.15.x

Then verify exactly which Python is being used:

python -c "import sys; print(sys.executable)"

Expected:

D:\vscode_python_practice\.venv\Scripts\python.exe

10. Install packages from requirements.txt

Now install your existing requirements:

uv pip install -r requirements.txt

UV will install the packages into your active .venv.

You can verify:

uv pip list

or:

pip list

11. Point VS Code to the new UV environment

This is important.

Press:

Ctrl + Shift + P

Search:

Python: Select Interpreter

Select:

.venv\Scripts\python.exe

It should correspond to:

D:\vscode_python_practice\.venv\Scripts\python.exe

12. Verify from VS Code

Open a new terminal.

You should see:

(.venv) PS D:\vscode_python_practice>

Run:

python --version

Then:

python -c "import sys; print(sys.executable)"

You should get:

Python 3.15.x

D:\vscode_python_practice\.venv\Scripts\python.exe

Complete command sequence

If you already have requirements.txt, the clean process is:

cd D:\vscode_python_practice

deactivate

uv --version

uv python install 3.15

Remove-Item -Recurse -Force .venv

uv venv --python 3.15

.\.venv\Scripts\Activate.ps1

python --version

python -c "import sys; print(sys.executable)"

uv pip install -r requirements.txt

Then in VS Code:

Ctrl + Shift + P
        ↓
Python: Select Interpreter
        ↓
.venv\Scripts\python.exe

One important recommendation for your PySpark setup

Before committing to Python 3.15, check your PySpark version:

findstr pyspark requirements.txt

If your project contains PySpark, Python 3.12 or 3.13 may currently be a much safer choice than 3.15 because the PySpark/Python compatibility matrix and third-party packages matter.

 #################

 

(.venv) PS D:\vscode_python_practice> cd D:\vscode_python_practice
(.venv) PS D:\vscode_python_practice> python --version
Python 3.13.15
(.venv) PS D:\vscode_python_practice> python -c "import sys; print(sys.executable)"
D:\vscode_python_practice\.venv\Scripts\python.exe
(.venv) PS D:\vscode_python_practice> deactivate
PS D:\vscode_python_practice> python --version
Python 3.11.0
PS D:\vscode_python_practice> Remove-Item -Recurse -Force .venv

PS D:\vscode_python_practice> Get-ChildItem


    Directory: D:\vscode_python_practice


Mode                 LastWriteTime         Length Name                                       
----                 -------------         ------ ----                                       
-a----        29-09-2026     16:09            246 Program to show args and kwargs in python  
                                                  copy.py                                    
-a----        29-09-2026     16:41            916 python Version Check.py                    

You should still have:

D:\vscode_python_practice
│
├── requirements.txt
├── your_python_files.py
└── ...


PS D:\vscode_python_practice> powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"                                                                            
downloading uv 0.12.23 (x86_64-pc-windows-msvc)                                               
installing to C:\Users\rajanikanta\.local\bin
  uv.exe
  uvx.exe
  uvw.exe
everything's installed!

To add C:\Users\rajanikanta\.local\bin to your PATH, either restart your shell or run:

    set Path=C:\Users\rajanikanta\.local\bin;%Path%   (cmd)
    $env:Path = "C:\Users\rajanikanta\.local\bin;$env:Path"   (powershell)
PS D:\vscode_python_practice> 


Close VS Code and Reopen :


PS D:\vscode_python_practice> uv --version
uv 0.12.23 (46b84fd0b 2026-10-03 x86_64-pc-windows-msvc)



PS D:\vscode_python_practice> Test-Path .venv
False
PS D:\vscode_python_practice> uv venv .venv --python 3.13.15
Using CPython 3.13.15
Creating virtual environment at: .venv
Activate with: .venv\Scripts\activate
PS D:\vscode_python_practice> .\.venv\Scripts\Activate.ps1
(.venv) PS D:\vscode_python_practice> python --version
Python 3.13.15
(.venv) PS D:\vscode_python_practice> python -c "import sys; print(sys.executable)"
D:\vscode_python_practice\.venv\Scripts\python.exe
(.venv) PS D:\vscode_python_practice> 



D:\vscode_python_practice
│
├── .venv
├── requirements.txt
└── your_python_file.py



(.venv) PS D:\vscode_python_practice> uv pip install -r requirements.txt



(.venv) PS D:\vscode_python_practice> uv pip install -r requirements.txt
Resolved 122 packages in 957ms
Prepared 122 packages in 12.97s
░░░░░░░░░░░░░░░░░░░░ [0/122] Installing wheels...warning: Failed to hardlink files; falling back to full copy. This may lead to degraded performance.
         If the cache and target directories are on different filesystems, hardlinking may not be supported.
         If this is intentional, set `export UV_LINK_MODE=copy` or use `--link-mode=copy` to suppress this warning.
Installed 122 packages in 52.96s
 + anyio==4.15.1
 + argon2-cffi==25.1.0
 + argon2-cffi-bindings==26.1.0
 + arrow==1.4.0
 + asttokens==3.0.2
 + async-lru==2.3.0
 + attrs==26.1.0
 + babel==2.18.0
 + beautifulsoup4==4.15.0
 + bleach==6.4.0
 + certifi==2026.7.22
 + cffi==2.1.1
 + charset-normalizer==3.5.2
 + colorama==0.4.6
 + comm==0.2.3
 + contourpy==1.4.0
 + cycler==0.12.1
 + debugpy==1.8.22
 + defusedxml==0.7.1
 + executing==2.2.1
 + fastjsonschema==2.22.2
 + filelock==4.0.11
 + fonttools==4.66.1
 + fqdn==1.6.0
 + fsspec==2026.9.0
 + h11==0.16.0
 + httpcore==1.0.9
 + httpx==0.28.1
 + huggingface-hub==0.36.2
 + idna==3.20
 + ipykernel==6.29.5
 + ipython==9.17.1
 + ipython-pygments-lexers==1.1.1
 + ipywidgets==8.1.9
 + isoduration==20.11.0
 + jedi==0.20.0
 + jinja2==3.1.6
 + json5==0.15.0
 + jsonpointer==3.1.1
 + jsonschema==4.25.0
 + jsonschema-specifications==2025.9.1
 + jupyter==1.1.1
 + jupyter-client==8.10.0
 + jupyter-console==6.6.3
 + jupyter-core==5.9.1
 + jupyter-events==0.12.1
 + jupyter-lsp==2.3.1
 + jupyter-server==2.21.1
 + jupyter-server-terminals==0.5.4
 + jupyterlab==4.4.10
 + jupyterlab-pygments==0.3.0
 + jupyterlab-server==2.28.1
 + jupyterlab-widgets==3.0.17
 + kiwisolver==1.5.1
 + lark==1.3.1
 + markdown-it-py==4.2.0
 + markupsafe==3.0.4
 + matplotlib==3.11.2
 + matplotlib-inline==0.2.2
 + mdurl==0.1.2
 + mistune==3.3.4
 + mpmath==1.3.0
 + nbclient==0.11.0
 + nbconvert==7.17.1
 + nbformat==5.11.1
 + nest-asyncio==1.6.0
 + networkx==3.7
 + notebook==7.4.4
 + notebook-shim==0.2.4
 + numpy==2.3.1
 + packaging==26.3
 + pandas==2.3.0
 + pandocfilters==1.5.1
 + parso==0.8.7
 + pillow==12.3.0
 + platformdirs==4.12.3
 + prometheus-client==0.26.0
 + prompt-toolkit==3.0.53
 + psutil==7.2.2
 + pure-eval==0.2.4
 + pycparser==3.0
 + pygments==2.21.0
 + pyparsing==3.3.3
 + python-dateutil==2.9.0.post0
 + python-dotenv==1.1.1
 + python-json-logger==4.2.0
 + pytz==2026.5
 + pywinpty==3.0.5
 + pyyaml==6.0.3
 + pyzmq==27.2.0
 + referencing==0.37.0
 + regex==2026.9.29
 + requests==2.32.4
 + rfc3339-validator==0.1.4
 + rfc3986-validator==0.1.1
 + rfc3987-syntax==1.1.0
 + rich==14.0.0
 + rpds-py==2026.9.1
 + safetensors==0.8.0
 + send2trash==2.1.0
 + setuptools==84.0.0
 + six==1.17.0
 + soupsieve==2.10
 + stack-data==0.6.3
 + sympy==1.14.0
 + terminado==0.18.1
 + tinycss2==1.5.1
 + tokenizers==0.21.4
 + torch==2.7.1
 + tornado==6.5.10
 + tqdm==4.70.1
 + traitlets==5.16.1
 + transformers==4.53.2
 + typing-extensions==4.16.0
 + tzdata==2026.5
 + uri-template==1.3.0
 + urllib3==2.8.0
 + wcwidth==0.9.2
 + webcolors==25.10.0
 + webencodings==0.6.1
 + websocket-client==1.9.2
 + widgetsnbextension==4.0.16
(.venv) PS D:\vscode_python_practice> 

 

requirements.txt:

# Core environment
jupyter==1.1.1
notebook==7.4.4
ipykernel==6.29.5

# JSON validation
jsonschema==4.25.0

# Deep learning / GenAI
torch==2.7.1
transformers==4.53.2

# Data handling
numpy==2.3.1
pandas==2.3.0
matplotlib==3.11.2

# Utilities
rich==14.0.0
python-dotenv==1.1.1
requests==2.32.4

 

                                                                 

 

 

 

 

 

                                                                                                                                                                                                                                

 

 

 

 

 

No comments:

Post a Comment