繁体   English   中英

如何在非标准路径的Python 3.3安装中正确安装pip3?

[英]How do I correctly install pip3 in a Python 3.3 installation located at a non-standard path?

我有一台Ubuntu 16.04机器,它在/python/上有多个python 3安装,并且需要能够在它们之间随意切换。 这些版本之一是Python 3.3,直到Python 3.4.x才预安装了pip,因此我想将pip安装到此python安装中。 我不想使用发行版软件包,因为它实际上需要集成到/ python / python33安装中,我在管理此软件包时遇到了麻烦:

get-pip.py尝试在/usr/bin上卸载pip版本:

$ /tmp/get-pip.py --prefix /python/python33
Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 8.1.2
    Uninstalling pip-8.1.2:
Exception:
Traceback (most recent call last):
  File "/tmp/tmpdgdWPZ/pip.zip/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/tmp/tmpdgdWPZ/pip.zip/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/tmp/tmpdgdWPZ/pip.zip/pip/req/req_set.py", line 778, in install
    requirement.uninstall(auto_confirm=True)
  File "/tmp/tmpdgdWPZ/pip.zip/pip/req/req_install.py", line 754, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/tmp/tmpdgdWPZ/pip.zip/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/tmp/tmpdgdWPZ/pip.zip/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/usr/lib/python2.7/shutil.py", line 303, in move
    os.unlink(src)
OSError: [Errno 13] Permission denied: '/usr/bin/pip'
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

如果我添加--ignore-installed ,它不会出错,但仍在/ usr / bin中查看pip的版本(它抱怨的旧版本8.1.2):

$ /tmp/get-pip.py --ignore-installed --prefix /python/python33
Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-9.0.1
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

easy_install也不起作用:

$ export PYTHONPATH="$PYTHONPATH:/python/python33/"; /usr/bin/easy_install --prefix /python/python33 pip
TEST FAILED: /python/python33/lib/python2.7/site-packages does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /python/python33/lib/python2.7/site-packages

and your PYTHONPATH environment variable currently contains:

    '/pyqt/sip-4.13.1/site-packages:/pyqt/site-packages:/python/python33/'

Here are some of your options for correcting the problem:

* You can choose a different installation directory, i.e., one that is
  on PYTHONPATH or supports .pth files

* You can add the installation directory to the PYTHONPATH environment
  variable.  (It must then also be on PYTHONPATH whenever you run
  Python and want to use the package(s) you are installing.)

* You can set up the installation directory to support ".pth" files by
  using one of the approaches described here:

  https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations

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

为什么要尝试安装到/python/python33/lib/python2.7/site-packages 这是pip的python 2版本吗?

我在这里已经阅读了很多相关的答案,但是到目前为止,它们都没有帮助。

我在16.04 Ubuntu Box上安装了Python 3.5.2和3.6.3。

3.5.2是/ usr / bin上系统安装的版本,python3和python3.5的Symlinks指向该版本

3.6.3安装在/ usr / local / bin python3.6指向此版本

对我而言,以下作品:

wget https://bootstrap.pypa.io/get-pip.py
python3.6 get-pip.py
mkdir /home/ubuntu/myproj/venv
python3.6 -m venv /home/ubuntu/myproj/venv
#Activate the venv
source /home/ubuntu/myproj/venv/bin/activate

python3现在指向我的虚拟环境中的3.6。

您如何在16.04上安装Python 3.6。 我遭受了不折不扣的痛苦。 最后,我从源代码构建。 有关详细信息,请参见此要点 这个问题解释了为什么。 这篇博客文章为我提供了解决方案。

暂无
暂无

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

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