问题:如何安装没有root访问权限的python模块?
我正在上一些大学类,并且得到了“教学帐户”,这是我可以用来从事工作的学校帐户。我想在那台机器上运行需要大量计算的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.
How can I do the installation?
回答 0
在大多数情况下,最佳解决方案是通过运行以下命令来依赖所谓的“用户站点”位置(有关详细信息,请参阅PEP):
pip install --user package_name
以下是我原始答案提供的一种“更手动”的方法,如果上述解决方案适合您,则无需阅读它。
使用easy_install,您可以执行以下操作:
easy_install --prefix=$HOME/local package_name
它将安装到
$HOME/local/lib/pythonX.Y/site-packages
(“本地”文件夹是许多人常用的典型名称,但是您当然可以指定您有权写入的任何文件夹)。
您将需要手动创建
$HOME/local/lib/pythonX.Y/site-packages
并将其添加到您的PYTHONPATH
环境变量中(否则easy_install会抱怨-btw运行上面的命令一次,以找到XY的正确值)。
如果您没有使用easy_install
,请寻找一个前缀选项,大多数安装脚本都允许您指定一个。
使用pip可以使用:
pip install --install-option="--prefix=$HOME/local" package_name
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.
With easy_install you can do:
easy_install --prefix=$HOME/local package_name
which will install into
$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).
You will need to manually create
$HOME/local/lib/pythonX.Y/site-packages
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).
If you are not using easy_install
, look for a prefix option, most install scripts let you specify one.
With pip you can use:
pip install --install-option="--prefix=$HOME/local" package_name
回答 1
没有访问权限或安装权限easy_install
?
然后,您可以创建一个python virtualenv
(https://pypi.python.org/pypi/virtualenv)并从该虚拟环境中安装该软件包。
在shell中执行4个命令就足够了(为XXX插入当前版本,如16.1.0):
$ curl --location --output virtualenv-X.X.X.tar.gz https://github.com/pypa/virtualenv/tarball/X.X.X
$ tar xvfz virtualenv-X.X.X.tar.gz
$ python pypa-virtualenv-YYYYYY/src/virtualenv.py my_new_env
$ . my_new_env/bin/activate
(my_new_env)$ pip install package_name
来源和更多信息:https : //virtualenv.pypa.io/en/latest/installation/
No permissions to access nor install easy_install
?
Then, you can create a python virtualenv
(https://pypi.python.org/pypi/virtualenv) and install the package from this virtual environment.
Executing 4 commands in the shell will be enough (insert current release like 16.1.0 for X.X.X):
$ curl --location --output virtualenv-X.X.X.tar.gz https://github.com/pypa/virtualenv/tarball/X.X.X
$ tar xvfz virtualenv-X.X.X.tar.gz
$ python pypa-virtualenv-YYYYYY/src/virtualenv.py my_new_env
$ . my_new_env/bin/activate
(my_new_env)$ pip install package_name
Source and more info: https://virtualenv.pypa.io/en/latest/installation/
回答 2
您可以运行easy_install将Python软件包安装在主目录中,即使没有root访问权限。有一种使用site.USER_BASE的标准方法,默认为$ HOME / .local或$ HOME / Library / Python / 2.7 / bin之类,默认情况下包含在PYTHONPATH中
为此,请在主目录中创建一个.pydistutils.cfg:
cat > $HOME/.pydistutils.cfg <<EOF
[install]
user=1
EOF
现在,您可以在没有root特权的情况下运行easy_install:
easy_install boto
另外,这还可以让您在没有root访问权限的情况下运行pip:
pip install boto
这对我有用。
源自Wesley Tanaka的博客:http : //wtanaka.com/node/8095
You can run easy_install to install python packages in your home directory even without root access. There’s a standard way to do this using site.USER_BASE which defaults to something like $HOME/.local or $HOME/Library/Python/2.7/bin and is included by default on the PYTHONPATH
To do this, create a .pydistutils.cfg in your home directory:
cat > $HOME/.pydistutils.cfg <<EOF
[install]
user=1
EOF
Now you can run easy_install without root privileges:
easy_install boto
Alternatively, this also lets you run pip without root access:
pip install boto
This works for me.
Source from Wesley Tanaka’s blog : http://wtanaka.com/node/8095
回答 3
回答 4
重要问题。我使用的服务器(Ubuntu 12.04)拥有easy_install3
但没有pip3
。这是我将Pip和其他软件包安装到主文件夹的方式
要求管理员安装Ubuntu软件包 python3-setuptools
已安装点
像这样:
easy_install3 --prefix=$HOME/.local pip
mkdir -p $HOME/.local/lib/python3.2/site-packages
easy_install3 --prefix=$HOME/.local pip
- 添加Pip(以及其他Python应用程序到路径)
像这样:
PATH="$HOME/.local/bin:$PATH"
echo PATH="$HOME/.local/bin:$PATH" > $HOME/.profile
- 安装Python包
像这样
pip3 install --user httpie
# test httpie package
http httpbin.org
Important question. The server I use (Ubuntu 12.04) had easy_install3
but not pip3
. This is how I installed Pip and then other packages to my home folder
Asked admin to install Ubuntu package python3-setuptools
Installed pip
Like this:
easy_install3 --prefix=$HOME/.local pip
mkdir -p $HOME/.local/lib/python3.2/site-packages
easy_install3 --prefix=$HOME/.local pip
- Add Pip (and other Python apps to path)
Like this:
PATH="$HOME/.local/bin:$PATH"
echo PATH="$HOME/.local/bin:$PATH" > $HOME/.profile
- Install Python package
like this
pip3 install --user httpie
# test httpie package
http httpbin.org
回答 5
我使用JuJu,它基本上允许在$ HOME / .juju目录中有一个非常小的linux发行版(仅包含软件包管理器)。
它允许通过proot访问位于主目录中的自定义系统,因此,您可以安装没有root特权的任何软件包。它可以在所有主要的Linux发行版上正常运行,唯一的限制是JuJu可以在最低建议版本2.6.32的linux内核上运行。
例如,在安装JuJu以安装pip之后,只需键入以下内容:
$>juju -f
(juju)$> pacman -S python-pip
(juju)> pip
I use JuJu which basically allows to have a really tiny linux distribution (containing just the package manager) inside your $HOME/.juju directory.
It allows to have your custom system inside the home directory accessible via proot and, therefore, you can install any packages without root privileges. It will run properly to all the major linux distributions, the only limitation is that JuJu can run on linux kernel with minimum reccomended version 2.6.32.
For instance, after installed JuJu to install pip just type the following:
$>juju -f
(juju)$> pacman -S python-pip
(juju)> pip
回答 6
回答 7
在本地安装virtualenv(说明源):
重要提示:插入XXX的当前版本(如16.1.0)。
检查提取文件的名称,并将其插入YYYYY。
$ curl -L -o virtualenv.tar.gz https://github.com/pypa/virtualenv/tarball/X.X.X
$ tar xfz virtualenv.tar.gz
$ python pypa-virtualenv-YYYYY/src/virtualenv.py env
在使用或安装任何软件包之前,您需要使用source
虚拟Python环境env
:
$ source env/bin/activate
要安装新的python包(例如numpy),请使用:
(env)$ pip install <package>
Install virtualenv locally (source of instructions):
Important: Insert the current release (like 16.1.0) for X.X.X.
Check the name of the extracted file and insert it for YYYYY.
$ curl -L -o virtualenv.tar.gz https://github.com/pypa/virtualenv/tarball/X.X.X
$ tar xfz virtualenv.tar.gz
$ python pypa-virtualenv-YYYYY/src/virtualenv.py env
Before you can use or install any package you need to source
your virtual Python environment env
:
$ source env/bin/activate
To install new python packages (like numpy), use:
(env)$ pip install <package>