15

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.

0

2 Answers 2

7

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 (Windows: venv\Scripts\activate)

  3. pip install -r requirements.txt

  4. jupyter lab (or jupyter notebook)

Sign up to request clarification or add additional context in comments.

Comments

0

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

2 Comments

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.
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."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.