最近使用pip下载python包的时候发现,软件默认安装到了个人的home目录下,使得软件的使用权为个人。于是去搜索了一下如何安装到指定的目录下的方法,作为分享。是的,我比较喜欢分享,这里手动艾特一下以身作则的健明老师。
方法一:手动指定安装路径。
pip install --install-option="--prefix=绝对路径" packageName
如果是源代码的话。也可指定安装路径。
./configure --prefix=安装路径
###或者对make来说
make install DESTDIR=安装路径
方法二:一劳永逸,将默认的安装路径改为指定的安装路径。
回到pip。
首先,我们先查看一下默认的安装地址。命令行为:
/software/python3/Python-v3.7.0/bin/python3 -m site
如下图所示:我们看见这里的USER_BASE 和USER_SITE其实就是用户自定义的启用Python脚本和依赖安装包的基础路径,均是个人的home目录,也就是说安装的时候,默认会安装到个人home下面。

或采用下面方法直接查看USER_SITE,命令行为:
/software/python3/Python-v3.7.0/bin/python3 -m site --user-site

接下来去找到这个默认路径的脚本。命令行为:
python -m site -help

查看一下提示的脚本,修改其user-site。

首先该脚本中对该参数定义为:None

做了个判断,当为None的时候,默认的路径为个人home目录。
修改一下USER_SITE的定义即可,将None改为指定的路径。
下次安装好的包,就能快速进行定位了。
参考:
https://www.cnblogs.com/lenmom/p/10189140.html
https://www.jb51.net/article/149625.htm
网友评论