使用 pip 安装 Python 包

使用 pip 安装 Python 包

我尝试使用 pip 在 Ubuntu 17.04 上安装 pymemcache,但出现以下错误。虽然模块安装时没有 -t 选项。但我想将模块安装在特定目录中,以便我可以打包并上传到云端。

有人可以帮帮我吗?

pip install -t /home/praveen/Code/AWS/Lambda/Memcached-Py pymemcache



Collecting pymemcache
    Using cached pymemcache-1.4.3-py2.py3-none-any.whl
Collecting six (from pymemcache)
    Using cached six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six, pymemcache
Exception:
Traceback (most recent call last):
    File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
        status = self.run(options, args)
    File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 360, in run
        prefix=options.prefix_path,
    File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 784, in install
        **kwargs
    File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 851, in install
        self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
    File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 1064, in move_wheel_files
        isolated=self.isolated,
    File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 247, in move_wheel_files
        prefix=prefix,
    File "/usr/lib/python2.7/dist-packages/pip/locations.py", line 153, in distutils_scheme
        i.finalize_options()
    File "/usr/lib/python2.7/distutils/command/install.py", line 289, in finalize_options
        raise DistutilsOptionError("can't combine user with prefix, "
DistutilsOptionError: can't combine user with prefix, exec_prefix/home, or install_(plat)base

答案1

此问题是由Ubuntu 修补版本中的显式-t选项和隐式选项之间的冲突引起的。这在的 GitHub 存储库中有所描述,网址为--userpippiphttps://github.com/pypa/pip/issues/3826https://github.com/pypa/pip/issues/4390

为了避免这种情况,我建议使用虚拟环境。步骤如下:

  1. virtualenv如果尚未安装,请安装:

    sudo apt update
    sudo apt install virtualenv
    
  2. 创建并激活虚拟环境并升级pip

    virtualenv venv
    source venv/bin/activate
    pip install -U pip
    
  3. 使用以下选项安装pymemcache在您指定的目录中-t

    pip install -t /home/praveen/Code/AWS/Lambda/Memcached-Py pymemcache
    

相关内容