Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. # When creating virtulaenv with conda, if you're using PIP_REQUIRE_VIRTUALENV=true
  2. # You might end up with you cannot install by pip even you already activated the virtualenv
  3. # This patch is another approach to let your conda venv work with the PIP_REQUIRE_VIRTUALENV flag
  4. # By patching your pip library with this file, and add another flag CONDA_ENVS in your bashrc
  5. # For instance, export CONDA_ENVS="/Users/$USER/conda/envs"
  6. # Then, the pip flag should not prevent you installing anything in your conda venv anymore.
  7.  
  8. python_path=$(which python)
  9. python_version=$(echo "$(python -V 2>&1)" | grep -E -o '[0-9]{1,}\.[0-9]{1,}(\.[0-9]{1,})?' | grep -E -o '[0-9]{1,}.[0-9]{1,}')
  10. pip_version=$(conda list | grep pip | grep -E -o '[0-9]{2,}\.[0-9]{1,}(\.[0-9]{1,})?' | grep -E -o '[0-9]{2,}.[0-9]{1,}')
  11. pip_root=${python_path/bin\/python/lib/python$python_version/site-packages/pip}
  12. cur=$(pwd)
  13.  
  14. if [ 1 -eq "$(echo "${pip_version} < 19.2" | bc)" ] ; then
  15. filename=locations.py
  16. else
  17. filename=utils/virtualenv.py
  18. fi
  19.  
  20. while true; do
  21. echo "This will be the file which I am going to modify: $pip_root/_internal/$filename"
  22. echo "Please paste the path above IF it shows a prompt for the path to file, otherwise you're all good."
  23. read -p "ok for you? [Y/n] >> " yn
  24. echo ""
  25. case $yn in
  26. [Yy]* )
  27. cd $pip_root
  28. echo "diff --git a/_internal/$filename b/_internal/$filename
  29. index 380db1c3..db18befd 100644
  30. --- a/_internal/$filename
  31. +++ b/_internal/$filename
  32. @@ -15,6 +15,8 @@ def running_under_virtualenv():
  33. elif sys.prefix != getattr(sys, "base_prefix", sys.prefix):
  34. # PEP 405 venv
  35. return True
  36. + elif os.path.dirname(sys.prefix) == os.environ.get(\"CONDA_ENVS\"):
  37. + return True
  38.  
  39. return False" > ./pip.patch
  40. patch -p1 < ./pip.patch
  41. rm ./pip.patch
  42. echo "Please export a env variable call CONDA_ENVS with the path to your conda envs folder"
  43. cd $cur
  44. break
  45. ;;
  46. [Nn]* ) exit;;
  47. * ) echo "Please answer yes or no.";;
  48. esac
  49. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement