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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With