4

I seem to have lost all the python packages that I had on my Mac.

I entered the command below to upgrade from python3.6 to python3.7:

brew upgrade python

and now when I enter ipython3 in the terminal it says:

-bash: /usr/local/bin/ipython3: /usr/local/opt/python/bin/python3.6: bad interpreter: No such file or directory

However I was able to use ipython3 moments before I performed the brew upgrade. Furthermore, I think I have lost all my python packages because when I do an import module in Python3, it says:

ModuleNotFoundError: No module named *examplepythonpackage*

Are the python packages that I installed before all lost for good and do I have to re-install them individually now?

I also cannot run (in the bash terminal) $ipython3

-bash: /usr/local/bin/ipython3: /usr/local/opt/python/bin/python3.6: bad interpreter: No such file or directory

For reference:

$ which python
    /usr/bin/python
$ which python3
    /usr/local/bin/python3
$ pip --version
    pip 18.1 from /Library/Python/2.7/site-packages/pip-18.1-py2.7.egg/pip (python 2.7)
$ pip3 --version
    pip 18.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
piccolo
  • 2,093
  • 3
  • 24
  • 56
  • You upgraded from python 3.6 -> python 3.7 (from the pip3 output). You need to reinstall ipython3 to get it to work again as it's pointing at the python3.6 interpreter. You need to reinstall all the modules you had under python3.6 in python3.7 in order to get everything working again - none of them carry forward by default. – Anya Shenanigans Jan 24 '19 at 11:20
  • Possible duplicate of [pip3: bad interpreter: No such file or directory](https://stackoverflow.com/questions/51373063/pip3-bad-interpreter-no-such-file-or-directory) – floss Jul 23 '19 at 17:46

2 Answers2

1

The link between ipython and which Python interpreter and libraries it uses underneath is established at installation time (as opposed to dynamically every time you run it), so I think your problem will be resolved if you remove and then re-install ipython, i.e.:

brew rm ipython
brew install ipython

If you want to understand this, look at your ipython script like this:

more $(which ipython)
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • but ignoring ipython, even if I use `$Python3` (which works), the packages that I had seem to be gone when I do import _package_. Are they gone for good? :( – piccolo Jan 24 '19 at 11:19
  • Yes, I get that too. If you look at `PYTHONPATH` in your `ipython` script like I show at the end of my answer, it seems to contain `/usr/local/Cellar/ipython/.../python3.7/site-packages` and the `3.7` part means it won't find packages you installed under v3.6. I am not sure what you are supposed to do other than use `pip` to reinstall all the packages you need... – Mark Setchell Jan 24 '19 at 11:23
  • So just to confirm - the python packages that I installed before are lost for good and I have to reinstall them individually? – piccolo Jan 24 '19 at 11:26
  • I'm not that good on Python that I want to say that and cause you a load of work that may be unnecessary. Maybe add that into your question and hope a real Python expert wanders by and addresses it before assuming anything about carrying forward packages. – Mark Setchell Jan 24 '19 at 11:28
  • If you run `brew switch python` it may let you go back to your older version with the packages you had before - as long as you haven't done a `brew cleanup`... – Mark Setchell Jan 24 '19 at 11:36
  • I have tried your steps but I still can't run `ipython` or `ipython3` in the terminal – piccolo Jan 24 '19 at 12:25
  • 1
    It's very hard to help with *"I can't run python"*. Please click `edit` under your question and say **how** you tried to run `ipython`, **what** happened and also show the output of `type ipython` Thank you. – Mark Setchell Jan 24 '19 at 12:54
-2

Your packages are not gone but are invisible to your new python. You might try to trick python 3.7 into looking for packages inside the python3.6 directory but then many packages would not work, specifically extension packages since 3.6 and 3.7 are not ABI compatible.

Basically, an upgrade like this requires you to reinstall all packages.

Stop harming Monica
  • 12,141
  • 1
  • 36
  • 56