Idea
前端的npm自带了install的快捷命令i
Python的pip我也希望它有,于是就定制了一下(虚拟环境中)
- 注:只适用mac和linux
Code
修改pip文件的内容(其中第一行要用python的绝对路径)
#!/c/Users/Administrator/AppData/Local/pypoetry/Cache/virtualenvs/lulu-eoRvp-M4-py3.11/Scripts/python
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
if sys.argv[1:] and sys.argv[1] == 'i':
sys.argv[1] = 'install'
sys.exit(main())
Command
相当于激活虚拟环境后,在命令行执行如下操作:
export pip_path=`which pip`
cp $pip_path $pip_path.bak
rm -f $pip_path
touch $pip_path
echo '#!'"`which python`" > $pip_path
echo '# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == "__main__":
sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
if sys.argv[1:] and sys.argv[1] == "i":
sys.argv[1] = "install"
sys.exit(main())' >> $pip_path
- 注:只在虚拟环境中起作用
2024-05-31 补充:增加了git+https自动切ssh的功能,代码见https://github.com/waketzheng/carstino/blob/main/.pipi.py