MikeB2019x
MikeB2019x

Reputation: 1161

Trying to make sense of Python/Jupyter environment on MacOS

Background: while running Jupyter Notebook a new import was failing even though the library was installing successfully using pip3. Some of the set up for the code I was running was done in PyCharm which was using a virtual Python 3.8.2 environment. The failing import library is in the virtual environment so why isn't Jupyter seeing it?

I went looking and found that there are multiple versions of Python installed:

I have installed pyenv and virtualenv and tried (unsuccessfully) to sort things out through this and similar articles. But all of this has only left me with questions:

Upvotes: 2

Views: 2323

Answers (3)

MikeB2019x
MikeB2019x

Reputation: 1161

A few years later and here is how I now handle this situation:

  1. install miniconda
  2. for every python project create an environment using conda create <env name> python=3.10.8 (or whatever version you want)

This means that every python project has exactly the python version I specify. My workflow is basically:

  1. create git repo
  2. create env
  3. open env
  4. write a list of all packages in a requirements.txt file
  5. pip install all packages with pip install -r requirements.txt

The last one is important. I've always found my packages (data science) in pip but not always in conda, and mixing conda and pip packages has always led to tears. This way I keep it all pure.

Note: why miniconda and not venv? Because that's what all the devs in our office are using, no other reason.

Upvotes: 0

Kevin Danikowski
Kevin Danikowski

Reputation: 5196

After trying @Akbar30bill's answer without success I did brew doctor and restarted my terminal and tried again and it worked. Wasn't linked correctly or something.

Upvotes: 1

Akbar30bill
Akbar30bill

Reputation: 362

installing jupyter with pip from pyenv fixed my problem

brew uninstall jupyter
pip install jupyter

and after restarting your console it should be pyenv's jupyter

Upvotes: 2

Related Questions