簡體   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