- Published on
Set up python development environment
- Authors

- Name
- Jinjiu Liu
Content
Today I mainly set up the development environment on my mac, so this blog will explain how to set up multiple python with different versions and some simple git set up.
Multi Python Management by pyenv
For the context, I use zsh for the terminal and deploy multiple versions of python3 for software development.
Install
pyenvbybrewbrew install pyenvInstall different python versions by
pyenvpyenv versions # see what python pyenv installs, for me, it # doesn't see the ones installed by brew pyenv install 3.10.19 # install the versions you need pyenv install 3.12.12 # install the versions you need pyenv global 3.12.12 # set default for your user cd directory_of_your_project # go to your project using specific version pyenv local 3.10.19 # in a project dir, pins that version (writes .python-version) python -V # the version will be 3.10.19 when you are under this folderMake sure your
pyenvis initialized, for example, if you see different python versions of python and python3 after setting the local versionIn
~/.zprofile(for PATH at login) add:eval "$(pyenv init --path)"In
~/.zshrc(for interactive shells) add:eval "$(pyenv init -)"Then do
exec zsh
Git worktree set up
Git worktree is an amazing tool to maintain multiple versions of your project. For example, I have two versions to maintain for my project, master and 1.0.
- In my current repo, which the head is
master, get the branches
cd ~/code/myproject
git status # make sure it's clean
git fetch --all --prune
- Create a
1.0worktree folder
- If you already have
1.0in the remoteorgit worktree add ../myproject-1.0 origin/1.0git worktree add ../myproject-1.0 1.0_branch_name - If you want to create a new branch 1.0 from master:
git worktree add -b 1.0 ../myproject-1.0 master # (or pick another starting point: a tag, commit, or origin/master)
Now when you go to the folder myproject-1.0, you branch 1.0 is automatically checked out!