2017-12-12 3 views
0

Ich habe eine Ubuntu 16.04 Maschine, die mehrere Python 3 Installationen bei /python/ hat und in der Lage sein muss zwischen ihnen zu wechseln. Eine dieser Versionen ist Python 3.3, und pip war erst mit Python 3.4.x vorinstalliert, also möchte ich pip in diese Python-Installation installieren. Ich will nicht Distro von Paketen benutzen, weil es tatsächlich integrierte in die/Python/python33 Installation benötigt werden, ich habe Probleme der Verwaltung dieser:Wie installiere ich pip3 korrekt in einer Python 3.3-Installation, die sich in einem nicht standardmäßigen Pfad befindet?

get-pip.py versucht, die Version von pip auf /usr/bin zu deinstallieren:

$ /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. 

Wenn ich --ignore-installed hinzufügen, es Fehler nicht aus, aber immer noch an der Version von pip Blick auf/usr/bin (die alte 8.1.2 ein, dass es über beschwert):

$ /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 nicht funktioniert entweder:

$ 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. 

Und warum ist es, die versuchen, in /python/python33/lib/python2.7/site-packages zu installieren? Ist das die Python 2-Version von Pip oder so?

Ich habe viele ähnliche Antworten hier auf SO gelesen, aber keiner von ihnen hat bisher geholfen.

+0

Wenn Sie mehrere Versionen von Python verwenden möchten, sollten Sie virtualenv oder etwas ähnliches wie Conda verwenden. – chrisz

+0

Definitiv. Aber stellen wir uns vor, dass ich aus irgendeinem Grund nicht kann. Angenommen, ich bin in einer Unternehmensumgebung ... – iLikeDirt

+1

hast du versucht, '/ python/python33/tmp/get-pip.py'? – georgexsh

Antwort

0

Ich habe Python 3.5.2 und 3.6.3 auf einem 16.04 Ubuntu-Box installiert.

3.5.2 ist das System installierte Version in/usr/bin Symlinks für python3 und python3.5 Punkt auf diese Version

3.6.3 unter/usr/local/bin python3.6 Punkte installiert ist Für mich auf diese Version

folgende Arbeiten:

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 zeigt jetzt auf 3.6 in meiner virtuellen Umgebung.

Wie haben Sie Python 3.6 am 16.04 installiert? Ich hatte eine Welt der Verletzung, die es schaffte, Dinge nicht zu brechen. Am Ende habe ich aus der Quelle gebaut. Details hierzu finden Sie unter gist. Diese question erklärt warum. Und diese blog Post gab mir die Lösung.

+0

hast du versucht [diese ppa] (https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa)? – georgexsh

+0

Ja, und es funktioniert gut für Python 3.6 Das Problem ist, dass 16.04 Python 3.5 für Dinge wie apt-get auf Systemebene arbeiten benötigt. – WombatPM

+0

install python36 von deadsnake ppa nicht 'shadow system pyhton, hast du ein problem damit? – georgexsh

Verwandte Themen