python备忘录
Created 2021-10-10 / Updated 2022-09-14一、pip安装python包时使用清华大学的mirror:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
二、将python包安装到当前用户的家目录下:
pip install --user <...>
默认安装在~/.local
下,可以通过修改shell的PYTHONUSERBASE
变量更改路径:
export PYTHONUSERBASE=/home/xxx/python
需要将可执行文件的路径添加到shell的PATH
中:
export PATH=${PATH}:${HOME}/.local/bin
如设置了PYTHONUSERBASE
变量,则:
export PATH=${PATH}:${PYTHONUSERBASE}/bin
三、在安装bs4时出现以下警告,导致安装失败:
WARNING: Building wheel for bs4 failed: [Errno 13] Permission denied: ‘/home/…/.cache/pip/wheels/…/bs4-0.0.1-py3-none-any.whl’
解决方法:
加上--no-cache-dir
pip install --user bs4 --no-cache-dir
四、临时web服务器
python -m http.server --bind 服务器IP地址
默认共享当前目录,端口是8000。
五、升级包
列出可更新的包列表:
$ pip list --outdated
更新包:
$ pip install --upgrade --user <...>
参考:
- https://stackoverflow.com/questions/35519384/building-wheel-for-package-failed-permission-denied-when-using-pip-in-virtualen
- https://docs.python.org/3/library/http.server.html