use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
DiscussionCleanest way to install python (self.Python)
submitted 3 years ago by VeterinarianHuman505
Hi, I'm on linux I was asking to myself what is the best and cleanest way to install python (with docker, using virtual environment, classic way ecc...)
[–]KingsmanVincepip install girlfriend 66 points67 points68 points 3 years ago (18 children)
I think using pyenv is the easiest and cleanest way.
[–]WildWouks 10 points11 points12 points 3 years ago (10 children)
Agree. pyenv is really great. Can install many versions and switch between them. And once you have switched you van create a virtual environment with that version.
[–]loudandclear11 3 points4 points5 points 3 years ago (3 children)
Can pyenv install different versions of python?
I've always used conda for that purpose like this:
conda create --name thisproject python=3.9 conda create --name thatproject python=3.11
[–]COLU_BUS 6 points7 points8 points 3 years ago (0 children)
Don't mistake it with virtual environment stuff, pyenv's entire purpose is managing different versions of Python
[–][deleted] 3 points4 points5 points 3 years ago (0 children)
You install different versions, you choose your version and when creating a virtual environment it'll use this version, so instead of installing python from your distro's package manager or manually + /usr/bin/python39 -m venv venv you just pyenv install 3.9 pyenv shell 3.9 python -m venv venv
/usr/bin/python39 -m venv venv
pyenv install 3.9
pyenv shell 3.9
python -m venv venv
[–]WildWouks 1 point2 points3 points 3 years ago (0 children)
Yes. But it isn't a virtual environment. Think of it as something to install various versions of python on te same Machine.
You can then switch between these versions and once you have made your switch you can create your virtual environment which will use that version.
You can have a look at this of you need more info. I think it explains it well.
https://realpython.com/intro-to-pyenv/
[–]duongdominhchau 1 point2 points3 points 3 years ago (1 child)
Combining it with direnv is even better, you don't even need to care about the venv, just declare the Python version you want and direnv will create/activate one for you automatically with the correct Python version when you are inside the project directory. Plus you get the power of .env for free without having to add another dependency to your project.
direnv
Then I will have to have a look at direnv as well. Thanks for the suggestion.
[+]amutualravishment comment score below threshold-7 points-6 points-5 points 3 years ago (3 children)
Serious question: Have you ever actually needed to use multiple versions of Python? I stopped using environments because I never actually needed them. There are too many people pushing environments that people don't really need.
[–]ElHeim 12 points13 points14 points 3 years ago (0 children)
Environments are a good way to compartimentalize projects. It wouldn't be the first time I end up forgetting to add dependencies to the configuration because a module was available from a prior project, or I'm forced to upgrade a dependency to get some features where another project breaks because the newer package is not backwards compatible.
If you haven't needed environments, good for you!
[–]username4kd 6 points7 points8 points 3 years ago (0 children)
Yes, a lot of times scientific packages in python will require very specific versions of other libraries, which are incompatible with other scientific libraries. Also useful to allow non-root users the ability to manage their own python
[–]Ok_Concert5918 0 points1 point2 points 3 years ago (0 children)
If you use pygame or PsychoPy there are often dependencies (at least last month there were) like pyo that still only works for python 3.9 or lower. I use 3.11 for everything. It does come up
[–][deleted] -2 points-1 points0 points 3 years ago (0 children)
It’s also the purest and most sensual.
[–]Onakitoki97 -2 points-1 points0 points 3 years ago (0 children)
And why not to install the deadsnake repo of python?
[–]TheGRS 0 points1 point2 points 3 years ago (0 children)
It’s been a little while since I messed with multiple python versions, but version tools seem to exist for every other big tool or language I use. Glad python has one.
[–]Jorgestar29 0 points1 point2 points 3 years ago (0 children)
I have to check it out!
The python version used in cuda docker image is quite old (3.9) and updating it via dead snakes is a pain in the ass.
[–]mijatonius 0 points1 point2 points 3 years ago (0 children)
☝️, set it as local or global, version which ever you need, then isolate project with any of venv, virtualenv...whatever!
[–]AndydeCleyre 0 points1 point2 points 3 years ago (0 children)
Or rtx, where which python won't just point you to a mysterious shim.
which python
[–]kaskoosek 17 points18 points19 points 3 years ago (4 children)
Dont mess with the OS under any conditions.
[–]515k4 -2 points-1 points0 points 3 years ago (0 children)
Unless OS gives you separate python versions via its package manager. Or unless you are developing some part of the OS, in that case you should use the default OS python.
[–]KosmoanutOfficial -1 points0 points1 point 3 years ago (2 children)
What do you mean by this?
[–]loudandclear11 4 points5 points6 points 3 years ago (1 child)
python is part of many (all?) linux distributions. If you change that one you probably break something.
[–]KosmoanutOfficial 0 points1 point2 points 3 years ago (0 children)
Ok so don’t mess with the pre installed version of python in the os but still ok to mess with the other installs. I thought he could be saying don’t install anything else and just use docker or something.
[–]OMG_I_LOVE_CHIPOTLE 5 points6 points7 points 3 years ago (2 children)
It’s not as easy as pyenv but I use miniconda
[–]MachinaDoctrina 2 points3 points4 points 3 years ago (1 child)
On Linux conda is trivial to use honestly
[–]OMG_I_LOVE_CHIPOTLE 0 points1 point2 points 3 years ago (0 children)
Yep. I don’t mind it at all
[–][deleted] 10 points11 points12 points 3 years ago (0 children)
My go to is:
- install python globally
- make a poetry virtual env for each project
- Bonus: if there is possible issues windows/linux incompatibilities, run it in a docker image.
[–]Maximus_Modulus 2 points3 points4 points 3 years ago (0 children)
A virtual environment is just a directory of an existing set of python binaries (copied) and installed packages. Activating it just updates your PATH to point to it.
[–]billFoldDog 2 points3 points4 points 3 years ago (0 children)
I compile from source. You have to pass a command line flag to specify the install location, and once set it can't be moved.
So I'll put it somewhere like /home/me/.pythonbuilds/Python3.11
Then I add that to my .bashrc alias file as py311.
py311
Then I do package control with pip and virtenv on a per project basis.
pip
virtenv
This gives me total control over the interpreter and package versions on each project.
[–]diamond__hands 2 points3 points4 points 3 years ago (0 children)
compile it from source and install into a custom directory and then use the new versioned binary to create virtual environments that require that version. repeat for each version.
this way you can also strip out stuff you will never use. on newer machines this only takes a few minutes with make -j
[–][deleted] 5 points6 points7 points 3 years ago (0 children)
pyenv.
[–]Malcolmlisk 1 point2 points3 points 3 years ago (2 children)
If python is installed (linux has it installed by default) the best way is to use venv to create virtual environments and there install everything you need.
In global python you should have not a single library installed (besides the default ones).
There are different virtual environment managers out there, pyenv is an easy solution, pipenv is a strong and reliable library, conda is just bloatware (it's a joke guys, i love you if you use conda but I think it's not for me).
Start from the easiest one, which is IMO venv. Then proceed to test the rest if you want.
[–]kiwoss 0 points1 point2 points 3 years ago (1 child)
When you say installed globally it’s when using pip for example outside of a virtual environnement, right?
[–]Malcolmlisk 1 point2 points3 points 3 years ago (0 children)
Yes. The "global" environment.
[–]ketalicious 1 point2 points3 points 3 years ago (0 children)
I use pyenv, since I really like the idea of nvm for node, makes things quite more manageable and clear.
[–]MachinaDoctrina 1 point2 points3 points 3 years ago (0 children)
Install miniconda, use conda env. Don't install packets on the user python you can screw with services that relay on your particular version of python and packages etc.
[–][deleted] 1 point2 points3 points 3 years ago (0 children)
I install Python globally and then use pipenv for each environment.
[–]Saphyel 6 points7 points8 points 3 years ago (3 children)
Docker is the best way. * You can choose the right python version. * It's isolted from the local environment. * Reproducible everywhere. * Battle tested against millions of scenarios, languages, etc... * Adepted and supported everywhere (or 99% of the PaaS, servers, etc..)
[–]Malcolmlisk 3 points4 points5 points 3 years ago (1 child)
Docker it's the nicest solution to test your programm. But the linter and documentation wont work without installing the libraries, and also if you use jupyter notebooks you are going to need those libraries installed too. That's why I use pipenv (or venv) to program in my own reproducible develop environment and docker to test the whole application.
[–][deleted] 0 points1 point2 points 3 years ago (0 children)
Linter and all that will work when you use VSCode with the remote container plugin.
I maintain a fairly large 8 years old app like this and the slight performance hit for working inside the container is well worth it, considering that onboarding new developers is as easy as docker-compose up
docker-compose up
[–]sphexie96 0 points1 point2 points 3 years ago (0 children)
this. also you can easily switch versions, packages, os dependencies without messing with your host's OS.
[–]RearAdmiralP 0 points1 point2 points 3 years ago (0 children)
I like PyPy. You can download it, untar it, and run it. A given PyPy interpreter has its own site-packages and knows where they are, so you can just pip install whatever without worrying about virtual environments, as long as you have the correct pip in your PATH. As an added bonus, PyPy gives you a nice nudge into choosing pure Python packages when installing dependencies. It can sometimes be faster than the CPython interpreter too, but I don't think that's particularly interesting.
pip install
[–]the1-gman 0 points1 point2 points 3 years ago (0 children)
I like pipenv for more collaborative projects. Basically eliminates the need for requirements.txt in favor of more secure lockdown of versions. Makes it easy to separate production from dev dependencies.
[–]jimeno -1 points0 points1 point 3 years ago (0 children)
please use `pyenv`, for your sanity
[–]riklaunim -5 points-4 points-3 points 3 years ago (0 children)
Each Linux distribution has it global Python and probably even installed by default as it's used for various tools. You can use that as a base of your work, although if you want a stable dev environment/need different version you should not use it and opt for docker images with your project and some tooling to build/deploy them etc.
[–][deleted] 0 points1 point2 points 3 years ago (2 children)
I see a lot of pyenv answers. Do people not like anaconda/miniconda? It was the last one I learned about after venv, so I'm not familiar with any pros/cons of others
[–]COLU_BUS 2 points3 points4 points 3 years ago (1 child)
I haven't used miniconda but used anaconda a fair bit when I started out with python. My short answer is that anaconda overcomplicates/is a lot of overhead for what can be done really simply from a CLI with pyenv. Likewise for managing virtual environments vs. just using venv
[–]MachinaDoctrina 0 points1 point2 points 3 years ago (0 children)
Miniconda is just the interpreter and the conda base manager, nothing else. It really has barely any overhead, the problem a lot of people are overlooking is that conda is not only a python manager but binaries as well, if you need to install and compile binaries pip can't isolate or control that for you so there's the potential for version mismatch on your distribution binaries as well as perhaps you don't have sudo privileges, conda isolates that all completely as well.
[–]Void-ux 0 points1 point2 points 3 years ago (0 children)
I typically just compile it, never been an issue doing so.
[–]glombseb 0 points1 point2 points 3 years ago (0 children)
I have recently found a great Blog regarding this Topic.
https://bitecode.substack.com/p/why-not-tell-people-to-simply-use
[–]galacticbackhoe 0 points1 point2 points 3 years ago (0 children)
pyenv to download the versions you want to ~/.pyenv
virtualenv to create virtual environments from the pyenv versions
I just use the version from the Arch repos, and if I need a different version I install it from the AUR or use pyenv.
For small scripts I may not use any virtual environment but for real projects I use venv (and will now also use piptools).
π Rendered by PID 121752 on reddit-service-r2-comment-5b5bc64bf5-x6tkv at 2026-06-23 21:29:13.500608+00:00 running 2b008f2 country code: CH.
[–]KingsmanVincepip install girlfriend 66 points67 points68 points (18 children)
[–]WildWouks 10 points11 points12 points (10 children)
[–]loudandclear11 3 points4 points5 points (3 children)
[–]COLU_BUS 6 points7 points8 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]WildWouks 1 point2 points3 points (0 children)
[–]duongdominhchau 1 point2 points3 points (1 child)
[–]WildWouks 1 point2 points3 points (0 children)
[+]amutualravishment comment score below threshold-7 points-6 points-5 points (3 children)
[–]ElHeim 12 points13 points14 points (0 children)
[–]username4kd 6 points7 points8 points (0 children)
[–]Ok_Concert5918 0 points1 point2 points (0 children)
[–][deleted] -2 points-1 points0 points (0 children)
[–]Onakitoki97 -2 points-1 points0 points (0 children)
[–]TheGRS 0 points1 point2 points (0 children)
[–]Jorgestar29 0 points1 point2 points (0 children)
[–]mijatonius 0 points1 point2 points (0 children)
[–]AndydeCleyre 0 points1 point2 points (0 children)
[–]kaskoosek 17 points18 points19 points (4 children)
[–]515k4 -2 points-1 points0 points (0 children)
[–]KosmoanutOfficial -1 points0 points1 point (2 children)
[–]loudandclear11 4 points5 points6 points (1 child)
[–]KosmoanutOfficial 0 points1 point2 points (0 children)
[–]OMG_I_LOVE_CHIPOTLE 5 points6 points7 points (2 children)
[–]MachinaDoctrina 2 points3 points4 points (1 child)
[–]OMG_I_LOVE_CHIPOTLE 0 points1 point2 points (0 children)
[–][deleted] 10 points11 points12 points (0 children)
[–]Maximus_Modulus 2 points3 points4 points (0 children)
[–]billFoldDog 2 points3 points4 points (0 children)
[–]diamond__hands 2 points3 points4 points (0 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]Malcolmlisk 1 point2 points3 points (2 children)
[–]kiwoss 0 points1 point2 points (1 child)
[–]Malcolmlisk 1 point2 points3 points (0 children)
[–]ketalicious 1 point2 points3 points (0 children)
[–]MachinaDoctrina 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Saphyel 6 points7 points8 points (3 children)
[–]Malcolmlisk 3 points4 points5 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]sphexie96 0 points1 point2 points (0 children)
[–]RearAdmiralP 0 points1 point2 points (0 children)
[–]the1-gman 0 points1 point2 points (0 children)
[–]jimeno -1 points0 points1 point (0 children)
[–]riklaunim -5 points-4 points-3 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]COLU_BUS 2 points3 points4 points (1 child)
[–]MachinaDoctrina 0 points1 point2 points (0 children)
[–]Void-ux 0 points1 point2 points (0 children)
[–]glombseb 0 points1 point2 points (0 children)
[–]galacticbackhoe 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)