{
"path": "/posts/2023/clean-python-setup",
"site": "at://did:plc:mracrip6qu3vw46nbewg44sm/site.standard.publication/self",
"tags": [
"python",
"asdf"
],
"$type": "site.standard.document",
"title": "Clean Python Setup",
"updatedAt": "2023-03-07T01:16:52.000Z",
"description": "No frills Python projects",
"publishedAt": "2023-03-07T01:16:52.000Z",
"textContent": "Why bother?\n\nI create a bunch of little Python projects and I like to have them sandboxed and independent of each other.\nI also sometimes need to change which version of Python I am running due to requirements of dependencies.\nYour OS may come installed with Python but it's rarely a great idea to try and run your projects from it.\n\nHere's what I do:\n\nInstall asdf\n\nasdf is a tool version manager.\nThere are good docs on how install it depending on your setup and preferences, described here.\nOpen a new shell session after editing your shell rc file and validate you successfully installed asdf\n\nNext, add the Python plugin for asdf.\n\nYou can now install any version of Python.\n\nTo switch to the version you installed, run\n\nSetup a virtual environment from asdf managed Python\n\nTo start, see what versions of Python you've had asdf install.\nI have two versions:\n\nWe can see that our python is currently the asdf managed version of Python.\n\nWe can also validate it's the same version as asdf claims:\n\nLet's create a virtual environment.\nFirst cd to your project folder, then run:\n\nActivate the virtual environment and validate your shell is pointing to the virtual environment's python rather than asdf's.\nYou should also see that the virtual environment's version of Python is the same as asdf's.\n\nNext, let's switch Python versions.\n\nCreate a second virtual environment.\n\ndeactivate once more and your back to your standard shell with asdf managed python.\n\nIf you ever see Python code you want to try out on your own machine that requires dependencies, or when starting a new project, I recommend setting up a virtual environment for the version you need like this.\nOnce you have the virtual environment setup and activated, you can install any dependencies you need in a spot that won't affect your system install or any other projects.\n\nWhat's next?\n\nI've been hearing a lot about nix and direnv as a killer combo for managing dev environments.\nI'm hoping to try that out and might revist my setup here if it goes well.",
"canonicalUrl": "https://www.danielcorin.com/posts/2023/clean-python-setup"
}