New pc: how do I install python *correctly* this time?

I've got some years of python+data experience through work, but the environments were always already set up. I installed various pythons on my own laptop (RIP, asus strix), but it was something like the basic python from official site, via the conda installer, and various updates and packages over time. Needless to say, it was not a production-worthy environment, but it let me do my own hobby projects just fine.

I recently got a new laptop and am looking to install python "correctly" this time so I can work on more substantial projects. I mean like, clean install, proper PATH (though I don't know wtf this means), virtualenvs, all that jazz.

Can anybody recommend some guides or walkthroughs for this? Poking around I find a variety of "best python install" guides that don't all align on best practices. Yes, I use windows because I'm a pleb. In the future I might do another linux installation via some VM, but not yet.

Thanks!

Posted Oct 30, 2021, 12:05 AM UTC

1217
Diapolo10I write code for a living -- https://github.com/Diapolo10•

Perfectly fine to use Windows, that's my personal preference (combined with WSL).

I usually recommend using the standard Python installation, but if you're focused on doing data science Anaconda is technically a better fit. I'm going to assume you want a more generalised setup, so I'm going to explain the first one. Correct me later if you so wish.

So, simply go to python.org and download the latest version, or at least 3.9 if you're not sure what you need supports 3.10 yet. When you run the installer, to make stuff easier in the beginning check the box to add Python to PATH, then just let the installer do its thing. Finally, once installed, check the box to disable the path length limit just in case - you probably won't need it, but it doesn't hurt.

And that should be everything done for the basics. Virtual environments aren't a hard requirement on Windows if you ask me, but it's probably a good idea to get used to them. Personally I recommend using Poetry so that you don't have to worry about it at all yourself and because it's very modern, but you can get by without anything or by using the built-in venv if you so wish.

Since Python was added to PATH, you should have direct access to running python, pip, and any tools you might install via PyPI directly. If you didn't, you'd use them via the included py-launcher.

py -m pip

That is all. Use whatever editor you fancy, I like VS Code with Python but you should try out different ones and find one you like yourself.

9
Blazerboy65•

Virtual environments aren't a hard requirement on Windows if you ask me, but it's probably a good idea to get used to them.

Can you expand on this? How do you manage having multiple projects when conflicting dependencies and how do you ensure everyone working on the codebase can reproduce the build?

1
Diapolo10I write code for a living -- https://github.com/Diapolo10•

The main reason virtual environments are practically a requirement on Linux distros and Mac OS is because they depend on Python. So if you're using the system-provided Python, you don't want to mess with any of their libraries. That's where the virtual environments come in.

You're of course correct in that you can't by default manage projects with conflicting dependencies or create reproducible builds without additional tools. This is true no matter the operating system. However, in my opinion a beginner is less likely to run into the first scenario, and the second one comes more into play when working as a team. But if one was to need that, sure, virtual environments would be a solution.

I'll quote a comment I made the other day:

Though there is an alternative, and that would be PEP 582 and pdm.

pdm, as described above, can be thought of as Poetry that uses PEP 582 instead of a virtual environment. I recommend reading up on both, as I find it a very interesting alternative.

1
rainning0513•

FYI the installation speed with pdm slow like a fuck.

1
Blazerboy65•

Ah I see what you mean.

I though you were saying that venvs/isolation of dependencies was not necessary for developers or in general.

It makes sense to try not to overwhelm beginners.

1
Diapolo10I write code for a living -- https://github.com/Diapolo10•

I've seen plenty of posts here for that exact reason, mainly because PyCharm uses them by default and beginners aren't accustomed to that. If you ask me I'd say beginners shouldn't need to worry about it yet, they're still focused on learning, well, the basics. Like using their editor of choice, or basic Python syntax.

2
bbqbotOP•

Thanks, I think I'm going to go with the standard installer and then use Poetry, looks like a good tool. I've been using VS Code for a while, and plan to stick with it. Love some of the add-ons!

1
StarkillerX42StarkillerX42•

On Windows I'd recommend Anaconda. If you're worried about space, usr Miniconda instead, which is the same thing without a bunch of preinstalled stuff. Anaconda is the best way to get things running without prior experience. I use this as my go to reference.

On Unix, I have found pyenv with the virtualenv extension to be quite nice.

Both of these interact well with PyCharm and VSCode. I used to use PyCharm, which helps hold your hand when it comes to managing environments. VSCode is a little simpler, so you'll have to spend more time in a terminal (which is the best place to learn).

4
jdnewmil•

+1 for Miniconda without admin for data science on windows. Learn to always create your own environments... relying on the Anaconda base environment is a pretty quick way to end up with unsolvable dependencies, especially when you want to try out other people's code examples. Seems so innocuous, but such a trap.

2
ryrythe3rd•

Just to try to answer one of these concerns, for environments and installing packages on windows, I recommend poetry. I find it more intuitive than pip or similar tools

3
bbqbotOP•

Reading up on poetry now, thanks!

1
Illya_Sempai•

Hm I think the easiest way is to install pycharm and then go through their set up guide since that will get you running your scripts pretty easily without mucking around with your variables too much. I personally use pycharm on a VM and instead of using virtual env's click file then open on the script I want and pycharm does the work for me. If that is giving you problem's there is a gear icon somewhere you can click to change your default interpreter to /bin/python3. Message me if you have some questions or reply here I can do a clean install on windows and make a guide for you this weekend.

1
bbqbotOP•

I'm very much a VSCode kind of guy, but perhaps in the future I'll check out pycharm. I used to have access to an educator license, but since that's gone I have a hard time stomaching the price.

2
Illya_Sempai•

Ah if it's just for learning and personal projects you can use pycharm community edition to get some practice. Also the practice in setting up a Windows environment by following their guides can help you set up an environment for VSCode since adding to the windows path is the same.

1

Hi, sorry I'm late to the thread. What's a safe and trusted source I can download python from and install it on my computer? I want to get practicing as soon as possible.

1
Soccer_Vader•

Just for starting out, I recommend just sticking with replit.com. I know I started off on replit and for me the transition to an actual IDE like VSCode and PyCharm was slow.

But if you really want to I recommend download Python Offical CLI from their website or if you are lazy(like me) just download pycharm and it takes care of the Python Interpreter for you everytime you start a new project. I might add they also set up the virtual environment for you.

0
bbqbotOP•

Hadn't heard of repl.it before, thanks for the suggestion. Looks really neato!

1