- [[conda package manager]], [[python - virtual environments]], [[python - uv]] ```sh # check if the python version you want has been installed (e.g., Python 3.9) python3.9 # if command not found, download and install that python version from https://www.python.org/downloads/ # navigate to your working directory cd my_working_directory # create venv # python3.x -m venv your_environment_name # -m specifies the module python3.9 -m venv venv # activate venv source venv/bin/activate # deactivate venv deactivate # check python version python -V # list installed packages pip list # install package in venv pip install pandas ``` Using `venv` with [[vscode]] - open a folder in [[vscode]] first - open terminal in vscode, then install a virtual environment with `venv` (follow instructions above) - create a new python file and save it (this step will activate the Python extension in vscode) - select your python environment (select it via menubar - bottom left, or use command palette) - check `.vscode/settings.json` to ensure the `python.pythonPath` is set to the correct environment - if it's wrong, manually update it - open a new terminal to check if the correct python environment is automatically loaded - use `python -V` to check python version in terminal ## Copy/reuse venv folder across directories It's possible to copy/reuse a venv directory/folder across projects. Just make sure to change the `VIRTUAL_ENV` variable after copying/moving the venv folder. ``` # go inside venv/bin # find all the activate* files # open them and change the directory path to your new directory path ``` - [Copy venv from one folder to another and still be able to use it? - DEV Community](https://dev.to/geekypandey/copy-venv-from-one-folder-to-another-and-still-be-able-to-use-it-3m49) # References - https://www.python.org/downloads/ - https://stackoverflow.com/questions/22681824/how-do-i-use-different-python-version-in-venv-from-standard-library-not-virtua - https://realpython.com/lessons/setting-up-environment-pandas-venv/