作者x246libra (宸火)
看板Python
标题[问题] Linux环境 询问pip3 套件安装管理问题
时间Sun May 20 15:50:54 2018
环境是ubuntu
尝试发文请教,不过我猜应该没人知道
我尽可能地描述
想了解一下 linux的权限问题 以及 第三方库管理套件是否真的被移除
问题1
用第三方库pip3 安装套件
pip3 install jupyter
没加sudo 无法找到 jupyter指令
即使重新安装 加上sudo指令也无法使用
这个我真不知道怎麽改善
若不是使用虚拟机可以回复初始状态
我就卡死在这边
若一开始就用以下指令
sudo pip3 install jupyter
可以找到jupyter指令
可正常使用
问题2
sudo pip3 install jupyter
安装时会出现警告,建议我或许可以加上-H
加上-H後确实不会出现警告
但是我不明白-H有什麽作用 又是为了什麽?
以下是测试过程的描述及图片
都是用虚拟机 回复初始状态
分3种情况 测试jupyter指令
1.sudo pip3 install jupyter
2.sudo -H pip3 install jupyter
3.pip3 install jupyter
------------------------------------------------------------------------
sudo apt-get install python3-pip 顺利执行安装
whereis pip3
pip3: /usr/bin/pip3 /usr/share/man/man1/pip3.1.gz
which pip3
/usr/bin/pip3
------------------------------------------------------------------------
再来使用pip3安装套件
sudo pip3 install jupyter
出现警告 但依然执行安装
The directory '/home/caesar/.cache/pip/http' or its parent directory is not
owned
by the current user and the cache has been disabled.
Please check the permissions and owner of that directory.
If executing pip with sudo, you may want sudo's -H flag.
https://imgur.com/ioCZTJa.jpg
安装jupyter後,测试jupyter指令
https://imgur.com/vsjlOn8.jpg
pip3 uninstall jupyter
执行失败,权限不足
https://i.imgur.com/q5jJD5s.jpg
sudo pip3 uninstall jupyter
出现警告 ,解安装成功
反安装jupyter後,测试jupyter指令
单独执行 jupyter 还是存在该指令 不是解安装了吗?
到底移除了什麽?
但若是用pip3 show jupyter 查询
则找不到jupyter套件
https://i.imgur.com/BTvL9o5.jpg
------------------------------------------------------------------------
为了不出现警告 尝试加上参数-H
sudo -H pip3 install jupyter
顺利安装 没出现任何警告
查询了-H的功能 在stackoverflow 看到以下这篇
https://stackoverflow.com/questions/43623025/what-does-sudo-h-do
但依然不太了解
加上-H 跟 没加上的差异 是为了什麽?
安装jupyter後,测试jupyter指令
感觉跟没用-H的 看起来相同
https://i.imgur.com/TKNoSmF.jpg
反安装jupyter 加上-H 不会出现警告
不明白有什麽差异
为了什麽目的 他建议我加上-H ?
https://i.imgur.com/cdh7ch3.jpg
------------------------------------------------------------------------
使用pip3安装套件 但是不加上sudo
pip3 install jupyter
没出现警报 正常安装
安装jupyter後,测试jupyter指令
找不到jupyter指令
我自己可以发现的差异只有
加上sudo的安装 使用pip3 show jupyter 其安装位置
/usr/local/lib/python3.6/dist-packages
没有sudo的安装 使用pip3 show jupyter 其安装位置
/home/caesar/.local/lib/python3.6/site-packages
https://i.imgur.com/DSDSVyO.jpg
由於jupyter指令 找不到
尝试 pip3 uninstall jupyter 解除安装
再用 sudo pip3 install jupyter 重新安装
安装过程 出现 许多Requirement already satisfied:...
例如:
Requirement already satisfied: nbconvert in
./.local/lib/python3.6/site-packages (from jupyter)
感觉也不是真的重新安装?
https://i.imgur.com/erH9I1U.jpg
重新加上sudo 安装 依然找不到jupyter指令
------------------------------------------------------------------------
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 111.241.13.97
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1526802657.A.BB4.html
1F:→ djshen: PATH 05/20 16:07
2F:推 TitanEric: 看过一篇文章是不要用sudo pip 05/20 22:16
3F:→ TitanEric: 好像都推荐用pip install xxx --user的样子 05/20 22:16
你说的那篇 应该类似这原因
https://bit.ly/2LepC9a
There was recently malicious code included in pypi. Never use sudo to install
with pip. This is the same as running a virus as root. Either add your local
folder to your PATH or use a virtualenv.
但是 单纯用 pip3 uninstall jupyter
就是 没办法使用 jupyter指令
似乎要另外增加到 $PATH
如果一开始用 sudo pip3 install jupyter
可以使用 jupyter指令
在解除安装 sudo pip3 uninstall jupyter
似乎只移除了/usr/local/lib/python3.6/dist-packages/jupyter-1.0.0.dist-info
/usr/local/bin 还是存在 jupyter 档案
所以 解除安装後 还是可以使用 jupyter指令
这种种都让我疑惑
※ 编辑: x246libra (111.241.13.97), 05/20/2018 22:33:09
4F:推 TitanEric: 试试sudo apt auto-remove? 05/21 00:29
5F:推 s860134: 善用 which 你才能知道你执行的 pip 是谁 05/21 19:50
6F:→ s860134: 有没 sudo 的差别可以用env 检查看看 05/21 19:59
7F:→ s860134: 他安装位置不同应该差在环境变数不一样 05/21 20:00