How to install python3 version of package via pip on Ubuntu?

前端 未结 17 1748
粉色の甜心
粉色の甜心 2020-11-22 11:03

I have both python2.7 and python3.2 installed in Ubuntu 12.04.
The symbolic link python links to python2.7

相关标签:
17条回答
  • 2020-11-22 11:32

    Although the question relates to Ubuntu, let me contribute by saying that I'm on Mac and my python command defaults to Python 2.7.5. I have Python 3 as well, accessible via python3, so knowing the pip package origin, I just downloaded it and issued sudo python3 setup.py install against it and, surely enough, only Python 3 has now this module inside its site packages. Hope this helps a wandering Mac-stranger.

    0 讨论(0)
  • 2020-11-22 11:34

    I had the same problem while trying to install pylab, and I have found this link

    So what I have done to install pylab within Python 3 is:

    python3 -m pip install SomePackage
    

    It has worked properly, and as you can see in the link you can do this for every Python version you have, so I guess this solves your problem.

    0 讨论(0)
  • 2020-11-22 11:34

    You can alternatively just run pip3 install packagename instead of pip,

    0 讨论(0)
  • 2020-11-22 11:35

    If you have pip installed in both pythons, and both are in your path, just use:

    $ pip-2.7 install PACKAGENAME
    $ pip-3.2 install PACKAGENAME
    

    References:

    • http://www.pip-installer.org/docs/pip/en/0.8.3/news.html#id4
    • https://github.com/pypa/pip/issues/200

    This is a duplicate of question #2812520

    0 讨论(0)
  • 2020-11-22 11:35

    Execute the pip binary directly.

    First locate the version of PIP you want.

    jon-mint python3.3 # whereis ip
    ip: /bin/ip /sbin/ip /usr/share/man/man8/ip.8.gz /usr/share/man/man7/ip.7.gz
    

    Then execute.

    jon-mint python3.3 # pip3.3 install pexpect
    Downloading/unpacking pexpect
      Downloading pexpect-3.2.tar.gz (131kB): 131kB downloaded
      Running setup.py (path:/tmp/pip_build_root/pexpect/setup.py) egg_info for package pexpect
    
    Installing collected packages: pexpect
      Running setup.py install for pexpect
    
    Successfully installed pexpect
    Cleaning up...
    
    0 讨论(0)
  • 2020-11-22 11:37

    Ubuntu 12.10+ and Fedora 13+ have a package called python3-pip which will install pip-3.2 (or pip-3.3, pip-3.4 or pip3 for newer versions) without needing this jumping through hoops.


    I came across this and fixed this without needing the likes of wget or virtualenvs (assuming Ubuntu 12.04):

    1. Install package python3-setuptools: run sudo aptitude install python3-setuptools, this will give you the command easy_install3.
    2. Install pip using Python 3's setuptools: run sudo easy_install3 pip, this will give you the command pip-3.2 like kev's solution.
    3. Install your PyPI packages: run sudo pip-3.2 install <package> (installing python packages into your base system requires root, of course).
    4. Profit!
    0 讨论(0)
提交回复
热议问题