Troubles when installing python package with Jupyterlab


I am able to run python scripts without package, e.g., a .py file with one line print(“Hello”). When I ran a .py file with numpy, I got this:

(base) JM-MacBook-Pro:chapter_14 john$ python3
Traceback (most recent call last):
  File "", line 3, in <module>
    from numpy import median
ModuleNotFoundError: No module named 'numpy'

I tried to install lumpy with pip3, but I got this

(base) JM-Pro:chapter_14 john$ pip3 install numpy
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at
Requirement already satisfied: numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (1.8.0rc1)

I got the same message if I type pip instead of pip3. How may I fix it?


The subject if your post and the text in it seem to be at odds. Your title has ‘with JupyterLab’ but what you post looks to be an example of you trying to run things on the command line in your machine’s system directly (Maybe?). So if what I’m going to suggest doesn’t get at what you need, you may need refine what you mean or what you are doing.

First, to address your issue in your title ‘with JupyterLab’. It looks from that you may just want to run Python 3 scripts and you already have JupyterLab installed. Let’s start with that assumption. Open JupyterLab and stay in JupyterLab’s notebook interface for now. In notebook cell, type pwd. You should get a directory that is the current working directory. Move your to there it it isn’t already. (You may be able to simply drag and drop into the panel on the left.) In the next cell, try running it with %run If it works, then you can at least run your script in a notebook in JupyterLab. If you get the ModuleNotFoundError, then type the following in the next cell %pip install numpy. Now try running the cell with %run again. I suspect it will work now. If it doesn’t yet, you may want to give running %conda install numpy in another cell a try and then try the %run cell again. (I don’t have the references handy right now and since I’m not 100% sure this is the direction you want, you have to take my word for it that running %pip install <package_name>
or %conda install <package_name> in cells are the current best way to install things into the environment backing your JupyterLab.)

As for the actual text of your post, I’m going to suggest you still do what I said above. Try all those steps to get your script that needs to import numpy running in JupyterLab. I’m hoping after you get things working in your notebook interface that you can open a terminal window via your JupyterLab session (not your Mac’s terminal program directly), and in that terminal window opened from JupyterLab, that you can now run python and it will work. I’m guessing it will work now because you went through installing things correctly in the environment JupyterLab is working from. Hopefully, that is sufficient for your needs. It’s hard to tell from what you posted, but I suspect are seeing stuff about Python 2.7 because what you pasted wasn’t from within where JupyterLab was running, maybe.

1 Like
  • I think the answer by fomightez is right on. Here are a couple of additional tips in troubleshooting:
    • Jupyterlab may run in its own conda environment, or non-conda environment. First, find out which/where jupyterlab is running. You can do that with ‘which jupyterlab’ or ‘which jupyter-lab’ from Mac bash terminal, or within the Jypterlab terminal, or
    • Programatically, you can also run a simple python code (in a notebook cell or python in Jupyter teminal):
      import sys
      print(sys.version) # find out if you are running 2.7 or 3.x
      print(sys.executable) # print the python you are using
1 Like

Thank you fomightez and hikemtshasta!! Your help me so much!!

1 Like