# When Jupyter Notebooks Won't Import Libraries

DevFeed: [When Jupyter Notebooks Won't Import Libraries](<https://devfeed.tech/articles/when-jupyter-notebooks-won-t-import-libraries-28228.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/python/2020/01/03/when-jupyter-notebooks-won-t-import-libraries.html>)

Author: Fuzzygroup

Published: 2020-01-03T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [jupyter](<https://devfeed.tech/topics/jupyter.md>), [Jupyter Notebook](<https://devfeed.tech/topics/jupyter-notebook.md>), [pip](<https://devfeed.tech/topics/pip.md>)

Tags: [data-science](<https://devfeed.tech/tags/data-science.md>), [import](<https://devfeed.tech/tags/import.md>), [jupyter](<https://devfeed.tech/tags/jupyter.md>), [jupyter-notebooks](<https://devfeed.tech/tags/jupyter-notebooks.md>), [libraries](<https://devfeed.tech/tags/libraries.md>), [python](<https://devfeed.tech/tags/python.md>)

## AI overview

The author could not get Jupyter Notebook working cleanly with a Python VENV after trying to install Jupyter inside the environment, follow two sets of directions, and change the kernel. Their workaround is to export the notebook as a Python script, create a requirements.txt, translate imports to package index names (which may differ, such as sklearn to scikit-learn), install with pip3, then run the script and adjust dependencies as needed. They report this generally works but expect changes. The author also notes that notebooks do not include their data, which remains an external dependency.

## Source excerpt

I don't claim to be an expert when it comes to Python. At best I'm an apprentice striving to be a journey man. One of the interesting tools in the Python / Data Science ecosystem is the Jupyter Notebook which gives a cell based representation of code, visualizations, documentation and execution flow and allows you to package things up for distribution i.e. hand your work, in a complete fashion, from say Data Scientist 1 ("Rebekah") to Data Scientist 2 ("Dawn"). This is a laudable goal and one that I theoretically agree with. Note: Jupyter Notebooks do NOT include data so that's still external to the notebook, something that can easily bite you (as it is currently biting me). I know a lot of pythonistas simply install libraries to their local machine and just have a collection of tools that the throw at problems. This, however, is a terrible practice due to code deprecation, version conflicts, etc. I say this with authority because I've been through this in the Ruby world before we all regularly started using Ruby virtual environments / Ruby version managers like RBENV / RVM which manage dependencies on a per project basis. Knowing this, my first practice with Python, is to always create a virtual environment, generally using Virtual ENV (VENV). So, when I set out today to use a Jupyter Notebook, my first approach was to make this work with a Jupyter Notebook. And, alas, I haven't been so lucky as to make this work cleanly with a Python virtual environment like VENV. Here are some of the things I tried: Installing jupyter into the virtual env and running from bin/jupyter notebook Following Angelo Basille's Directions Following Janakiev's Directions Changing the Kernel If you're curious about how to use Python Virtual Environments, I wrote a solid tutorial back in September that I used to get a full installation of Tensor Flow up and running. I've referred back to this over and over, each time I needed a Python Virtual Environment, so I know it works. I'm sure there i