Installing Python virtual environments on Windows using pyenv and vscode's terminal Salesforce tix 8868

 

3/14/2025 05:44:37

https://www.youtube.com/watch?v=Zn5tmx0ynw8
This Alejandro video is for Mac, how about Windows there, bud?

(winget is like apt install for Windows--did you know that? i have used it for PSH but not for the W11 OS at large It does not abstract PATH changes however it seems....at least for installing python)

We want to install pyenv windows port.
pyenv is not native to windows.

https://github.com/pyenv-win/pyenv-win #home page for pyenv-win port.
Powershell install didn't work--used git to install.


#First install git. From terminal elevated to local admin

winget install git.git

#followed instructions here.
https://github.com/pyenv-win/pyenv-win/blob/master/docs/installation.md#git-commands

#install using git.

git clone https://github.com/pyenv-win/pyenv-win.git "$HOME\.pyenv"

#set PATH Variables using these 4 statements from terminal run as local admin
[System.Environment]::SetEnvironmentVariable('PYENV',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")

[System.Environment]::SetEnvironmentVariable('PYENV_ROOT',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")

[System.Environment]::SetEnvironmentVariable('PYENV_HOME',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")

[System.Environment]::SetEnvironmentVariable('path', $env:USERPROFILE + "\.pyenv\pyenv-win\bin;" + $env:USERPROFILE + "\.pyenv\pyenv-win\shims;" + [System.Environment]::GetEnvironmentVariable('path', "User"),"User")

#check pyenv.

pyenv --version

#works!
PS C:\Users\cl> pyenv --version
pyenv 3.1.1
PS C:\Users\cl>

#use pyenv to install latest Python build!
pyenv install 3.13


#Fuck yeh! That frigging worked. The path changes needed to run new v. python from terminal are abstracted and set as well. Good luck getting that with done with winget.

PS C:\Users\cl> pyenv install 3.13
:: [Info] :: Mirror: https://www.python.org/ftp/python
:: [Info] :: Mirror: https://downloads.python.org/pypy/versions.json
:: [Info] :: Mirror: https://api.github.com/repos/oracle/graalpython/releases
:: [Downloading] :: 3.13.2 ...
:: [Downloading] :: From https://www.python.org/ftp/python/3.13.2/python-3.13.2-amd64.exe
:: [Downloading] :: To C:\Users\cl\.pyenv\pyenv-win\install_cache\python-3.13.2-amd64.exe
:: [Installing] :: 3.13.2 ...
:: [Info] :: completed! 3.13.2


#use pyenv to install an older python!
pyenv install 3.10

#Check version for me this is "system" version (installed via the OS or with winget)
PS C:\Users\cl> python --version
Python 3.10.10
Python 3.12.9
PS C:\Users\cl>

#set 3.13 via pyenv instead.
PS C:\Users\cl> pyenv global 3.13
PS C:\Users\cl> pyenv versions
* 3.13.2 (set by C:\Users\cl\.pyenv\pyenv-win\version)
PS C:\Users\cl>

#mkdir a new directory in Dropbox Python
mkdir ide-test-pyenv

#launch vscode

code D:\dropbox\python\ide-test-pyenv\

(note, you can create a new profile that only has Python extension--cool! I called this "python" Then File > open with profile)

#Within VSCODE
View > open view > terminal

#Now you can issue pyenv commands from within vscode

#set the local version

PS D:\Dropbox\python\ide-test-pyenv> pyenv local 3.13
PS D:\Dropbox\python\ide-test-pyenv> pyenv versions
3.10.11
* 3.13.2 (set by D:\Dropbox\python\ide-test-pyenv\.python-version)
PS D:\Dropbox\python\ide-test-pyenv>

#from terminal, create virtual environment files and folders inside of "ide-test-pyenv" subdir

python -m venv venv

#from terminal activate the virtual environment (note diff syntax since i am running windows)
#NOTE!!! you have to do this each time you start up vscode, vscode will not put you back into the venv right away.

venv/scripts/activate

#we have VENV!
(venv) PS D:\Dropbox\python\ide-test-pyenv>

#where is python running from? Note that "which python" doesn't work on windows. Instead use this:
where.exe python
#take the first path in the list.

============same thing on LINUX=========
I am using linux mint 3/17/2025 14:31:59

sudo apt update && sudo apt upgrade
sudo apt install python3.xxx-venv #install special "create venv" binary
go to root directory.

mkdir [name of project]
cd [name of project]


sudo python3 -m venv venv #create a virtual env using the root 'venv'

source venv/bin/activate #instantiate the virtual env.

sudo chown -R $(whoami):$(whoami) venv #make sure venv stuff is owned by current user, not root

pip install [blah blah]

Comments

Popular posts from this blog

Python POOP: "name mangling"--how to make class data private or public (odd in Python!)

Python POOP: static, class methods

MAKING SOME POOP==Python classes constructor and instantiating; class variables