如何在没有root访问权限的情况下安装python模块? [英] How to install python modules without root access?
问题描述
我正在上一些大学课程,并获得了一个教学帐户",这是一个我可以通过 ssh 登录的学校帐户来完成工作.我想在那台机器上运行我的计算密集型 Numpy、matplotlib、scipy 代码,但我无法安装这些模块,因为我不是系统管理员.
I'm taking some university classes and have been given an 'instructional account', which is a school account I can ssh into to do work. I want to run my computationally intensive Numpy, matplotlib, scipy code on that machine, but I cannot install these modules because I am not a system administrator.
我该如何安装?
推荐答案
在大多数情况下,最好的解决方案是依赖所谓的用户站点"位置(请参阅 PEP 详情)运行:
In most situations the best solution is to rely on the so-called "user site" location (see the PEP for details) by running:
pip install --user package_name
以下是我原始答案中更手动"的方式,如果上述解决方案适合您,则无需阅读.
Below is a more "manual" way from my original answer, you do not need to read it if the above solution works for you.
使用easy_install,您可以:
With easy_install you can do:
easy_install --prefix=$HOME/local package_name
将安装到
$HOME/local/lib/pythonX.Y/site-packages
(本地"文件夹是很多人使用的典型名称,但当然您可以指定您有权写入的任何文件夹).
(the 'local' folder is a typical name many people use, but of course you may specify any folder you have permissions to write into).
您需要手动创建
$HOME/local/lib/pythonX.Y/site-packages
并将其添加到您的 PYTHONPATH
环境变量中(否则 easy_install 会报错——顺便说一下,运行上面的命令一次以找到 X.Y 的正确值).
and add it to your PYTHONPATH
environment variable (otherwise easy_install will complain -- btw run the command above once to find the correct value for X.Y).
如果您不使用 easy_install
,请查找前缀选项,大多数安装脚本都让您指定一个.
If you are not using easy_install
, look for a prefix option, most install scripts let you specify one.
您可以使用 pip:
pip install --install-option="--prefix=$HOME/local" package_name
这篇关于如何在没有root访问权限的情况下安装python模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!