• superweeniehutjrs@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    23 days ago

    Can I request a hack? How do I handle several different versions of Python installed, which one is used for pip stuff, and how sudo/running as services changes all of this.

    • bjorney@lemmy.ca
      link
      fedilink
      arrow-up
      9
      ·
      edit-2
      23 days ago

      There are like 10,000 different solutions, but I would just recommend using what’s built in to python

      If you have multiple versions installed you should be able to call python3.12 to use 3.12, etc

      Best practice is to use a different virtual environment for every project, which is basically a copy of an existing installed python version with its own packages folder. Calling pip with the system python installs it for the entire OS. Calling it with sudo puts the packages in a separate package directory reserved for the operating system and can create conflicts and break stuff (as far as I remember, this could have changed in recent versions)

      Make a virtual environment with python3.13 -m venv venv the 2nd one is the directory name. Instead of calling the system python, call the executable at venv/bin/python3

      If you do source venv/bin/activate it will temporarily replace all your bash commands to point to the executables in your venv instead of the system python install (for pip, etc). deactivate to revert. IDEs should detect the virtual environment in your project folder and automatically activate it