11

I am a Python programmer, new to IPython Notebook. I have started a notebook that uses numpy.

If I was publishing the same code as a standalone Python script, I'd include a requirements.txt file with numpy and its version, so that other users can install the same version into a virtualenv when they run the script.

What is the equivalent of this for iPython Notebook? I can't find anything about managing requirements in the documentation, only about the dependencies required to install IPython itself.

My requirements are that I'd like to make sure that the notebook is using a particular version of numpy, and I want to make sure that I can publish the notebook with the same version specified.

Richard
  • 52,447
  • 93
  • 287
  • 475

2 Answers2

4

If you have Jupyter in your requirements.txt and you activate that environment (I recommend Virtualenv), install, and run Jupyter, you'll have all the specific versions you want. So:

  1. python3 -m venv venv

  2. source venv/bin/activate (different command on Windows)

  3. pip install -r requirements.txt

  4. jupyter lab (or jupyter notebook)

Boris Yakubchik
  • 2,387
  • 1
  • 24
  • 30
0

You can do this by importing numpy and then checking numpy.__version__. Related question here.

Community
  • 1
  • 1
Bennett Brown
  • 4,727
  • 1
  • 23
  • 33
  • 1
    I think OP's question is more general. This approach will only work for a small subset of packages and is quite cumbersome for multiple dependencies. – cel Nov 03 '15 at 05:09
  • I'm basing my answer on @dawg 's comment in the post to which I link: "The use of `__version__ `is recommended in PEP8... Most packages support `__version__`... Parse the version (and create your own version strings) as recommended in PEP 386 / PEP 440." – Bennett Brown Nov 03 '15 at 05:16