简体   繁体   English

Python / Linux-以非root用户身份手动安装httplib2

[英]Python/Linux - Manually installing httplib2 as a non-root user

I am trying to manually install httplib2 as a non-root user on a Linux machine. 我试图以非root用户身份在Linux计算机上手动安装httplib2。 The reason I am doing it manually is because I do not have the permissions to install pip. 我手动执行此操作的原因是因为我没有安装pip的权限。 I downloaded the httplib2-0.9.2.tar.gz file from https://pypi.python.org/pypi/httplib2 on my local machine (Mac) and used scp to transfer it to my Linux Machine. 我从本地计算机(Mac)上的https://pypi.python.org/pypi/httplib2下载了httplib2-0.9.2.tar.gz文件,并使用scp将其传输到Linux机器上。

After extracting the tar.gz file, I ran the following commands: 解压缩tar.gz文件后,我运行了以下命令:

[me@host ~]$ cd httplib2-0.9.2
[me@host httplib2-0.9.2]$ ls
MANIFEST.in  PKG-INFO  python2  python3  setup.cfg  setup.py
[me@host httplib2-0.9.2]$ python setup.py install
running install
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 13] Permission denied: '/usr/lib/python2.6/site-packages/test-easy-install-50310.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /usr/lib/python2.6/site-packages/

Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

  http://peak.telecommunity.com/EasyInstall.html

Please make the appropriate changes for your system and try again.

Since it said that I needed to install in a different directory if I am not a root user via --install-dir, I then ran: 由于它说如果我不是通过--install-dir的root用户,则需要在其他目录中安装,因此我运行:

[me@host httplib2-0.9.2]$ python setup.py install --install-dir /home/directory/me/
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: option --install-dir not recognized

Running '$python setup.py --help-commands' gave the following: 运行'$ python setup.py --help-commands'提供了以下内容:

Standard commands:
  build             build everything needed to install
  build_py          "build" pure Python modules (copy to build directory)
  build_ext         build C/C++ extensions (compile/link to build directory)
  build_clib        build C/C++ libraries used by Python extensions
  build_scripts     "build" scripts (copy and fixup #! line)
  clean             clean up temporary files from 'build' command
  install           install everything from build directory
  install_lib       install all Python modules (extensions and pure Python)
  install_headers   install C/C++ header files
  install_scripts   install scripts (Python or otherwise)
  install_data      install data files
  sdist             create a source distribution (tarball, zip file, etc.)
  register          register the distribution with the Python package index
  bdist             create a built (binary) distribution
  bdist_dumb        create a "dumb" built distribution
  bdist_rpm         create an RPM distribution
  bdist_wininst     create an executable installer for MS Windows
  upload            upload binary package to PyPI

Extra commands:
  rotate            delete older distributions, keeping N newest files
  develop           install package in 'development mode'
  setopt            set an option in setup.cfg or another config file
  saveopts          save supplied options to setup.cfg or other config file
  egg_info          create a distribution's .egg-info directory
  upload_docs       Upload documentation to PyPI
  nosetests         Run unit tests using nosetests
  alias             define a shortcut to invoke one or more commands
  easy_install      Find/get/install Python packages
  bdist_egg         create an "egg" distribution
  install_egg_info  Install an .egg-info directory for the package
  test              run unit tests after in-place build

usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

What command am I supposed to use to continue to install httplib as a non-root user? 我应该使用什么命令来继续以非root用户身份安装httplib? Completely blocked because of this issue. 由于此问题而被完全阻止。

Thanks in advance! 提前致谢!

You're on the right track. 您走在正确的轨道上。 Notice the line 注意行

The installation directory you specified (via --install-dir, --prefix, or ...

In this case you need to use --prefix . 在这种情况下,您需要使用--prefix Also you need to create the packages folder and export it to PYTHONPATH 另外,您需要创建packages文件夹并将其exportPYTHONPATH

So this should do it 所以应该这样做

INSTALL_DIR=${HOME}/.local
TREE=${INSTALL_DIR}/lib/python2.7/site-packages
mkdir -p ${TREE}
export PYTHONPATH=$PYTHONPATH:$TREE

python setup.py install --prefix=$INSTALL_DIR

I found this link helpful. 我发现此链接很有帮助。

Edit 编辑

Or you can simply try python setup.py install --user . 或者您可以简单地尝试python setup.py install --user See the user scheme 查看用户方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM