Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Library not loaded" error after upgrade python with Homebrew

I use pipenv to create virtualenv like this

pipenv --python /usr/local/bin/python3

After upgrade python with Homebrew, like python 3.7.2 to 3.7.3, active virtualenv with pipenv shell, and do anything with python will be error like this

python3 --version
dyld: Library not loaded: @executable_path/../.Python
  Referenced from: /Users/xxx/.local/share/virtualenvs/xxx-xxx/bin/python3
  Reason: image not found
[1]    60198 abort      python3 --version

All I know about this is /usr/local/bin/python3 is still there, run python on system level is good. Only call python in virtualenv will be wrong.

For now I have remove the virtualenvs and create it with pipenv again, it will fix this. But do these things will lost all pip packages, so I need to reinstall them again.

So, dose there have some smart way to solve this problem? Or what is happen during Homebrew upgrade python?

Maybe this question looks stupid. But I have been confused for a long time.

Thanks in advance.

like image 953
ESoragoto Luo Avatar asked Apr 29 '19 07:04

ESoragoto Luo


1 Answers

I had the same problem. The missing library is .Python which is a link that is at the top level of the virtual env (in your case /Users/xxx/.local/share/virtualenvs/xxx-xxx). If you go there and do ls -l .Python you can see that it points toward a specific homebrew Cellar directory (in my case /usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/Python). This directory was probably removed by the update (do ls -l /usr/local/Cellar/python to find out the new directory/version.

Remove the link and let it point to the new location, e.g. for me: ln -s /usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/Python .Python

like image 132
Gerriet Avatar answered Oct 19 '22 20:10

Gerriet