263 points · by kylebarron · 5y ago · 140 comments
Over an hour later I had to give up. There was initially some kind of Python version conflict on my Mac. Eventually some version of JupyterLab was installed somewhere, but it couldn't find any dependencies for the notebook. As a complete newbie to the Python ecosystem, I googled for instructions and found various environment managers, which then failed possibly because something is incompatible with Big Sur. More googling revealed instructions with complex CFLAGS environment setups to fix it, which didn't — and at that point it was very far from the supposed convenience of scripting languages anyway.
I don't think it's Python's fault. Probably all the programming toolchains are this hard to a newbie! But it was a humbling experience after 34 years of programming, not being able to load a piece of sample code in a Sunday afternoon.
Well, there's a long legacy of half-baked solutions and kludges. And, especially, install instructions consistently suggest you do the worst thing: install stuff using pip.
Everyone knows that's bad advice, because it always fails in mysterious ways, and there's no good way to roll everything back.
I recommend:
python3 -m pip install pipx # Don't rely on the pip3 bin.
pipx install jupyterlab
# Now jupyter has an independent virtualenv.
# To install dependencies:
pipx inject jupyterlab numpy
# Where is everything?
pipx list
venvs are in /Users/ben/.local/pipx/venvs
apps are exposed on your $PATH at /Users/ben/.local/bin
...
Once you've done that, never install anything directly with pip3 again. If you're working on a project, use pipx to install poetry / dephell / pipenv and use them to manage the virtualenv.And you can get rid of it all:
pipx uninstall-all
python3 -m pip uninstall pipxAs an aside; it is really hard to explain why you should use anything but pip3 to people who only rarely need to interact with python.
And I agree, it's hard to explain not using pip3, so I just wouldn't. "For the best experience, pipx install neato-commando." And maybe link to the pipx website, in case someone actually clicks a link.
The video discusses python packaging in general. You have to skip through several minutes of pre-roll though. https://www.youtube.com/watch?v=tNlurLxcf68&feature=emb_logo
My (extended) team couldn't even get all the Pythonistas to agree on The One True Python Stack™.
Looking at the amount of polish on the Python docs and the fact that people still don't know how to install Python, it gives you a sense of how hard explaining things is. Maybe the Python site could do with an official "managing Python for end-users."
> Noob me found all sorts of howtos and getting started guides. Seemingly contradictory, mutual exclusive.
Python's a victim of its own success as the signal to noise ratio in online tutorials is very low; worse, the good management tools are relatively new.
Even for smaller audiences, obsolescence is a big problem. The most painful aspect of working with LaTeX was I'd struggle with one buggy package recommended by a tutorial for ages, then search for "why am I getting this error" and find the answer was, "oh, yeah, that's horribly broken, use this one instead."
[1]: https://www.python.org/doc/sunset-python-2/ [2]: https://www.python.org/doc/versions/
I ended up putting off learning Python for years as this kind of stuff kept happening (first the 2/3 transition, and then massive pip breakage).
OSX and its tooling are just ridiculous. I have no idea to this day how macs became the premier development environment.
As always xkcd has a comic for it: https://xkcd.com/1987/
Because:
(a) it's quite easy to set things up with brew, macports, and/or Nix
(b) because Python is shitty everywhere anyway, and Python isn't the be-all end-all of development work.
(c) because you get a full-featured, working, coherent, take-it-or-leave-it desktop that stops one way of endless tinkering and procrastinating available in Linux to get things "just right"
(d) because it's still a UNIX with a full support for unicy tools, not a hack like WSL or WSL2.
(e) because it has good hardware (mostly - BS keyboard-era aside) and good resale value
(f) because you get to enjoy most/all the proprietary tools you like too (from MS Office and Adobe Creative Suite, to whatever)
(g) because in 2020 Docker, remote environments, etc, make many "local dev environment" points moot anyway
The entire point of this thread is that (a) is false -- see grandparent and the xkcd joke. It's not easy. It pretends to be easy, but is usually broken in some crazy way instead. Apt is also easy, but it actually works more often than not.
(c) was relevant in 2006, when the novelty of OS X was that it was a UNIX that you could actually use as a daily driver. This is what initially got developers to move to Mac. But it's been fifteen years, and all jokes aside, the "year of the Linux desktop" for developers was probably around 2012. Linux may still have issues, but they're not worse than the hoops you have to jump through to make today's macOS behave.
Trendy tech companies are still buying macbook pros for their employees because that's what's been trendy for the last decade, not because they actually ask new hires what they prefer. Practical tech companies do, and at places like that you usually see a mix of macs and thinkpads.
I've been editing a tutorial one of my coworkers wrote that targets new Python users on Windows. From my findings, the grass is not greener.
Granted, geospatial Python is somewhat of a mess, but a lot of tools I have to use are somewhat messy forks of Unix tools (looking at you, pyenv-win) with tons of incompatible extensions. For development, Windows is the exception because you can transfer just about anything from Linux to macOS.
On my Mac, I can easily install all of the Python packages I need without needing to install Visual Studio, pipwin, anaconda, etc. I have bash/zsh as my default system shell. Maybe it's easier to native Windows users, but bash/brew is a much better combination than anything I've found in Windows.
WSL is a step in the right direction, but it still feels secondary. If a first-class terminal experience existed on Windows, I have a strong feeling that it could be the premier development environment, or at least closer to Mac.
Maybe I'm using it wrong, but it definitely hasn't been made clear on how to use it right.
Maybe check the other other side (Linux) - I found the grass is greener there - at least for Python (and programming tools in general). I'm very comfortable on the command-line, and moving from a pure Linux environment to OS X & brew felt like a huge downgrade, followed by random annoyances that remind you you are using inferior, non-GNU utilities:
$ ls my_dir -l
ls: -l: No such directory
Really - Mac OS? I know its minor, but that's just user-hostile and it happens every few weeks; I can't get over it.I've been using WinPython for a few years. It's the closest thing to "just works" that I've found, and non-programming colleagues have been able to install it successfully.
Because it works almost like an isolated "container," it's also possible to test your code on a clean install of WinPython to make sure it will run on someone else's computer before you share it.
I don't know the technical difference between WinPython and a true container, but you can have multiple WinPython installs on one machine, and they don't interfere with one another, or with a pre-existing mainstream Python installation on the same PC. So you can share your stuff without worrying about screwing up someone else's stuff.
s/macs/python
s/development environment/scripting language docker run -p 8888:8888 -v ~/Code/actual-project/:/home/jovyan jupyter/datascience-notebook
Note ~/Code/actual-project/ is a git repo or a mounted Google Drive folder. Moving from one machine to an other is pain-free.[1] https://jupyter-docker-stacks.readthedocs.io/en/latest/using...
Instead, use: docker run -p 127.0.0.1:8888:8888
/usr/bin/python3 -m venv ./venv # create a virtual environment in ./venv
./venv/bin/pip install wheel # optional
./venv/bin/pip install dep1 dep2 dep3 ...
./venv/bin/python ... # up and running
is enough to get started in most cases. Of course, all bets are off for GPU or Apple Silicon support...If you are in luck, your required libraries and appropriate versions are available as GNU Guix packages and you can use that.
As for the reason why this still hasn't happened? I'm guessing because it is because the people who care about reproducibility have found other ways to achieve it, and as a result have no need nor incentive to implement it as part of the notebook format. Also because, if someone is running notebooks at all they know enough to bootstrap the jupyter server, which is non-trivial, or they are using a managed environment (be it remote, conda, etc.) where they are blissfully unaware that all their code has massive implicit and undocumented context.
In the mean time I have implemented the start of an equivalent system for org files because the implicit environment is much worse given normal Emacs workflows. I have encountered some significant issues and considerations which the notebook ecosystem would have to deal with, and which the default python packaging ecosystem (or any ghettoized language specific packaging solution for that matter) is not equipped to handle.
The primary issues is that only language agnostic package managers can actually bootstrap the environment that is required. What do you do if someone doesn't have a toolchain to build numpy and they are on some strange arch where there are no wheels? Do you just fail? The 80% solution here is the one we have with conda or managed solutions. The 90% solution requires that all the language communities stop pretending that they are the only language in the world and stop wasting time on their bespoke package manager.
Well not really.
First, there is no link between a distribution package name (what you install with pip) and python package name (what you import).
e.g. The distribution package "foobar" can install the python package "baz". Well, it's even worst than that. There could be name space packages so multiple distribution package actually install parts of a python package. And there could be monkey patching.
Second, Python is not a static language. The import system is part of the interpretation of python code, and as such, is dynamic.
You have absolutely 0 guarantee that "import foo" on two different environments, even if they have the same version of package foo, will produce the same results. There could be an infinite amount of magic done in foo's __init__ that depend on other libraries being installed, etc.
Third, don't get me started on the actual version of these libraries.
Then comes the point, where one of your dependencies in conda simply wont install on the machine of your coworker or a windows machine of another coworker, or in your docker image and you are screwed, scrambling for the next package manager. Been there, experienced that.
I can only recommend to people not to go that route and to not get into trying to get the same environment on windows. A lot of headaches. It will be simpler to tell people to use another OS, if they want to use the same environment. Ultimately I ended up providing a virtual machine.
A managed solution -- Yes, this takes a lot of load off of the shoulders of people, who would like to actually get productive in other ways.
They've pretty much always been a moving target, haven't they? Nothing has ever been good enough that the community agrees "okay, this is it, we can stop churning on this tooling for a while".
Probably testing package managers is not a simple thing to do.
A: it works on my computer
B: then we'll ship your computer
and that's how docker was bornI used it for a semester in college, and it was next to unbearable. I can appreciate it as a fun little functional programming gimmick, but nothing more than that.
I could have done it in Python but portability was always the issue.
At my former job I had to make charts from pictures with English and Spanish lettering. Took me 30 minutes to have a working client that got installed in a dozen computers that afternoon.
I needed to also re-structure the companies file system for every computer in our company.
Personally I worked in audio video contract work from time to time and I was able to make a dozen short cut programs that actually saved my biscuit several times. I could have done it in python but the portability kicked my butt. Racket made executables super easy.
Also I went through How to Design Programs and I learned a ton.
Python is a little worse in that in pushes its dirtiness downstream to your users too.
Then remember to run pip using `python3 -m pip <command>` and use virtual environments (venv)
I stumbled on this a couple weeks ago and documented the process here https://flaviocopes.com/python-installation-macos/
I found the same problem with Ruby (old version preinstalled on macOS)
```
$ conda create -n {new_environment_name} python
$ conda activate {new environment name}
$ conda install jupyterlab
```
({new_environment_name}) ...$ python -m ipykernel install --user --name {new_environment_name} --display-name "Python ({new environment display name})"
The env won't be accessible in jupyter (lab or notebook) until you do this step.
[0] https://stackoverflow.com/questions/39604271/conda-environme...
https://www.anaconda.com/blog/anaconda-commercial-edition-fa...
conda install -c conda-forge jupyterlab=3[0] https://repl.it/ [1] https://repl.it/talk/templates/Jupyter-Notebook/49993
docker run -p 8888:8888 jupyter/scipy-notebook
Hoping to help clear some backlog, I tried to help with some ML & data pipeline house cleaning. Had never used Python before, but how hard could it be? OMG. One really doesn't appreciate ease and simplicity of multiple simultaneous JDK installs, all peacefully coexisting, until working on some python and nodejs projects.
Just running user space dev env via Docker was recently front paged here on HN. I believe that will become the norm.
Being a macOS user, I looked to see if there was something more lightweight. Like maybe a port of podman. Lighter than running a virtual Linux instance.
Again as a macOS user, I feel like I'm overdue to embrace the remote dev desktop set up. I've read that Googlers don't do any work locally; they all remote shell into servers running the tool stack. So very X Windows; what is old is new again.
It really throws me off the whole thing (Julia + Jupyter is even worse...) because I’m not keen on putting effort into stuff that nobody, myself included, will be able to use in a year or two.
While I know it has earned its praise for good reason -- as I'm sure all the data scientists I work with would attest to -- as an engineer, Python has been really frustrating to work with.
Dependency management hell isn't just a Javascript problem these days.
Actually it is:
That said, you would be up and running if you used conda.
And this is not the usual "just try distro X" Linux advocate BS when somebody has an issue with distro Y.
Conda does makes thing more user friendly by focusing on whole environments. Actually that's why it was built for.
Note that this applies for this situation. For other uses cases, e.g. deploying something to production, having used conda would have made your life more difficult.
I've been developing Mito (https://trymito.io), a spreadsheet extension to JupyterLab that allows you to edit a spreadsheet in a notebook as if you're editing Excel. You edit the spreadsheet, and Python code gets generated that corresponds to your edits.
Feedback on the above greatly appreciated. And congrats on the release :)
One thing to look into is figuring out some logic of cancellation to clean up the generated code. Even if you just checked back one step it would mean less Foo_Bar['D'] = 0.
I think saving the analyses in the home directory is defeating the purpose. One appeal of a notebook is that you can break all the steps out and show them to someone, add commentary, etc.
I'd want to use it interactively to figure out how to get my data looking the way I want, and then show off how the analysis works by pulling out non-interactive Step widgets that visualize changes into their own cells.
That said, I'm often doing stuff with numpy so I need the notebook to document exactly what the dimensions mean, why I did a "clever" thing, etc.
Also, as long as "import mitosheet" is hitting your analytics APIs, it's going to set off alarm bells if we try to use it inside our VPN. The compliance people are not likely to look at what it's sending or why, they'll just ban it and move on.
I just wish that the cloud providers would adopt it as the basis for their products.
I hope that these closed source commercial platforms give back something to the open source community around Jupyter once they get out of the red numbers.
I get that they feel the need to add their own features (collaboration etc) to distinguish themselves but it would be so much better if they had settled on a single UI.
Still, can't complain too much about an open source project, thanks to the team for all their hard work.
I've used it as a way to document data exploration for later use and as an interactive teaching tool. For that, being able to plot inline and embed interactive widgets is great. Also, mixing in rendered markdown content.
If you're using Jupyter to write python software and the software is the end result and not the data analysis/process, I think you might be doing it wrong.
Not that I'm discounting data scientists (or the like) who use it as their primary environment. Their end result is not a packaged/deployed software and the code itself is just ancillary. For those users, the code and environment is a tool, and the extra weight of what a full IDE (like VSCode or PyCharm) and the features they bring to the table are unnecessary and likely counter-productive.
Unfortunately it often ends up needing to be executed as a batch job or integrated into a pipeline, which then starts the fun job of extracting the code from the notebook piece by piece.
Jupyter having a plain text file format instead of json would make life so much easier, and vastly improve version control.
https://netflixtechblog.com/notebook-innovation-591ee3221233
https://netflixtechblog.com/scheduling-notebooks-348e6c14cfd...
We also publish AppBooks, which are automatically parametrized notebooks. However, we automatically detect and track experiments, and then we deploy models in the form of an endpoint to be invoked by consumers, with a convenience page for humans to invoke the code by sending JSON data, or uploading a CSV file.
2. Following from 1, notebooks are meant to be shared with output in place, so others can understand without executing code.
In terms of a flat file formats, there is actually a mark down extension which I would say is better than vscode's format because it is more standardised:
was doing this in emacs before there was a jupyter notebook..
as the name implies, notebooks aren't for development, they are for interactive, shareable presentation, and presentation that also works over HTTP without needing local tooling
VSCode's version is nice for sure, but not nearly as nice as being able to go back and read/modify old cells.
Maybe there's a non-hacky way to do this and I'm missing it?
For publishing interactive examples we use voila, which creates a dashboard version of the notebook for users.
Afaik it's a drop in replacement for conda using the same cli parse. Even has miniconda (micromamba).
Is mamba taking off with the recent (and upcoming) license changes that anaconda made? I’m not familiar with mamba though I’ve had my eyes open for an alternative to anaconda (also seen poetry mentioned a few times here).
[1] https://datacrayon.com/posts/tools/jupyter/theme-purple-plea...
Relatedly, I have a grand vision of having as part of my development environment a jupyter notebook always at hand, in which to explore data as necessary, whip up scripts, accumulate little helper functions, etc. Basically, any time I have that "hm, I wonder..." itch, I'd like to be able to quickly whip up a solution in my notebook. I'm a skilled developer in terms of larger systems, but have a weakness when it comes to very early stage "throwaway" scripts to answer ad-hoc questions.
I spent a few days trying to set up jupyterlab in an "ideal" way, so that I could have easy access to python libraries within my notebook, and also a reproducible environment since I plan to push my working directory to GitHub and would like to sync across different machines. I got confused by virtualenv vs venv, and tried conda to install libraries, but ran into various problems. Oh, and part of it was trying to have nbdev (from the fastai folks) as part of this toolkit.
Anyone have a setup like this that they use and want to share? Part of me wants to just throw in the towel and learn R and RStudio, since I've heard its ggplot is the best plotting library anyway.
The workflow for creating a new project looks like this:
1. Create a project directory (e.g. 'myproject') and `cd` into it. 2. `git init` 3. Fixate the Python version for that project with the `pyenv local` command (e.g. `pyenv local 3.8.6`). This creates a `.python-version` file that you can put under source control. Within the `myproject` directory tree, `python` will now be automatically resolved to the specified version. Your system Python (in fact, any other Python versions you might have installed) remain untouched. 4. Create a new poetry project (`poetry init`). This creates a `pyproject.toml` which contains project metadata + dependencies and can also be checked into git. 5. Add dependencies with `poetry add`. Here, you could for instance add Jupyter Lab (`poetry add jupyterlab`).
To access installed dependencies, such as the `jupyter lab` command, you can either execute one command in the virtualenv directly (`poetry run jupyter lab`) or spawn a shell (`poetry shell`). If you open a Jupyter Notebook that way, the packages installed in the virtualenv are directly available from within Jupyter Notebooks, without having to mess around with installing IPython kernels.
I like this approach, because it gives you full flexibility, while being portable and easy to use. It gets you around having to deal with conda (which I found to be frustrating at times). Also, you're not tied to the Jupyter frontends, but could e.g. just install `ipykernel` and open notebooks in VSCode.
[1](https://github.com/pyenv/pyenv/) [2](https://python-poetry.org/)
Edit: Moved the links
pipenv run python -m ipykernel install --user --name=this_directory
Then if I open Jupyter Lab I see "this_directory" as a listed kernel to create a notebook from.This allows me to manage Jupyter settings and plugins in one place rather than in each env, have multiple project's notebooks open in the same Jupyter Lab instance, etc.
So C++ is the natural choice.
Care to elaborate?
I've built some personal Docker images based on these with quite a lot of additional features installed including Ruby, OpenCL and lots of additional Python and R packages and JupyterLab extensions. It's been a bit hit and miss - with extension incompatibilities being a bit of an issue. I sync directories on the host machine with the Docker image and so have the benefit of editing in a full text editor (for non-notebook scripts).
I'm not a Python env expert so I've probably missed a few tricks but all seems to be working well now. Happy to help if you want to try this route and have any issues.
Btw after using JupyterLab for over a year now I'm a huge fan.
One thing I haven't figured out is about Jupyterlab's extension system, which previously requires node.js for delivery. It seems 3.0 removed that requirement, so I am hopeful with some tuning I can deliver the plugins in consistent way as well.
But you could just install conda and just `conda env export -n base` to export your environment.
I just wondered if anyone has any ideas how you go about this as I've been drawing a blank.
It's the UI platform Jupyter built to power JupyterLab but is also a general purpose UI framework.
I tried downloading the source and removing the majority of the bits, but, I just got absolutely nowhere and was hoping there was a library somewhere or a guide that would make this job much easier, however, I'm getting nowhere!
To be honest one of the worst things about JupyterLab I've found is the number of interesting extensions that look great but turn out to be unmaintained or overlap with others. It can be really confusing!
Once the vim and black extensions adopt the new extension distribution system, they should also be compatible with JupyterLab Classic.