3 ms·
But despite being terrible the Python import system is remarkably easy to get started in. And generally easy for beginners to work with (put all the code in the
by roenxi 5y ago
But despite being terrible the Python import system is remarkably easy to get started in. And generally easy for beginners to work with (put all the code in the same folder or "pip install").
There are some lessons here that other languages would do well to learn. Trouble importing 3rd party libraries must be a kiss of death for beginner engagement.
- awestroke 5y agoI disagree. I find it hard to get started in python. There are loads of package managers, so I don't know which one to pick. There are multiple different rules for for how imports work with local files. The standard library is full of of functions that one should not use any more, and you need to know which is which. Defining a main entrypoint consists of checking a magic __NAME__ constant. You have internalised all these quirks, and know how to work with/around them. Beginners haven't.
- pnt12 5y agoCounterpoints: Start with pip, the official package manager. You don't have to start with virtual envs: I didn't. I haven't ran into any function which I "should not use". You don't need an entry point, you can just write code in a file. Besides that, I don't see how much it differs from other languages with implicit entry points, where you need to match a certain name in your function. Imports: yes, those are annoying and confusing. I still struggle with those. Aditionally: package managers and virtual envs are a pain in the ass. Every year we're getting a new one which is supposed to solve the problems from the previous one, but doesn't, and the cycle goes on. The language should really solve this at the core instead of requiring community fixing, as it is a core part of any serious development.
- kortex 5y agoHonestly I have had very few issues with poetry, and the ones I've had, it's because I'm trying to use plugins, which are alpha right now. Dependency resolution just works. Editable installs just work. Building just works. Before that, I only had problems with virtual envs once, and it was due to bad hygiene with system python libs and deps. Moral of the story: don't. Unless it's necessary to bootstrap virtualenv or compiled libs, don't system install python. Good ol' get-pip.py and virtualenv.
- simlevesque 5y agoI disagree too... you can't even refer to a file in the same folder without using some magic (adding current folder to the path), which is a huge barrier when starting.
- mixmastamyk 5y agoCurrent folder is in the path by default.
- tasogare 5y agoNo. Python is a language I have to use infrequently, but I give up half of the time using a project found on GitHub because of missing depencies, the need to install a package manager to install another package manager to install dependencies, etc. The other day I spent some times fixing a docker image that was working fine few months ago but which was now failing because some Python package install returned an error. On the contrary, C projects tends to build with 3 commands and C# (often way bigger) with a single command, and without having to do magic things around "virtual environments".
- The_Colonel 5y agoI vividly remember the frustration when trying to make some very simple application imports working. There's a couple of gotchas, the biggest one being that you need to write imports based on where you expect to run your applications from. Perhaps obvious for experienced python devs, very much surprising for newcomers. And then I was quite shocked by the state of package managers in python. You need to learn pip, venv (with references to "virtualenv"), these are too low level, so you find pipenv, which is unbelievably slow (installing a single dependency can take 10 minutes), so you need to learn to use it with "--skip-lock", but then you lose locking ... I've never appreciated node's bundled "npm" so much before which mostly "just works".
- AlphaSite 5y agoPoetry is pretty great comparatively, since it handles both dependencies, locking and virtual environments for you, but it has slow resolution just like pip (since the new update), pyenv, pipenv, etc.