Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # When creating virtulaenv with conda, if you're using PIP_REQUIRE_VIRTUALENV=true
- # You might end up with you cannot install by pip even you already activated the virtualenv
- # This patch is another approach to let your conda venv work with the PIP_REQUIRE_VIRTUALENV flag
- # By patching your pip library with this file, and add another flag CONDA_ENVS in your bashrc
- # For instance, export CONDA_ENVS="/Users/$USER/conda/envs"
- # Then, the pip flag should not prevent you installing anything in your conda venv anymore.
- python_path=$(which python)
- 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,}')
- 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,}')
- pip_root=${python_path/bin\/python/lib/python$python_version/site-packages/pip}
- cur=$(pwd)
- if [ 1 -eq "$(echo "${pip_version} < 19.2" | bc)" ] ; then
- filename=locations.py
- else
- filename=utils/virtualenv.py
- fi
- while true; do
- echo "This will be the file which I am going to modify: $pip_root/_internal/$filename"
- echo "Please paste the path above IF it shows a prompt for the path to file, otherwise you're all good."
- read -p "ok for you? [Y/n] >> " yn
- echo ""
- case $yn in
- [Yy]* )
- cd $pip_root
- echo "diff --git a/_internal/$filename b/_internal/$filename
- index 380db1c3..db18befd 100644
- --- a/_internal/$filename
- +++ b/_internal/$filename
- @@ -15,6 +15,8 @@ def running_under_virtualenv():
- elif sys.prefix != getattr(sys, "base_prefix", sys.prefix):
- # PEP 405 venv
- return True
- + elif os.path.dirname(sys.prefix) == os.environ.get(\"CONDA_ENVS\"):
- + return True
- return False" > ./pip.patch
- patch -p1 < ./pip.patch
- rm ./pip.patch
- echo "Please export a env variable call CONDA_ENVS with the path to your conda envs folder"
- cd $cur
- break
- ;;
- [Nn]* ) exit;;
- * ) echo "Please answer yes or no.";;
- esac
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement