在Windows上为特定版本的Python安装'pip'包

时间:2016-07-28 14:55:22

标签: python python-2.7 module

我的机器(Windows 10)有两个版本的python:3.5 2.7
我需要使用 pip 安装软件包,但我想要两者都使用该软件包。

我的默认版本是3.5。

我尝试这样做:pip2 install scikit-learn将它安装在python 2.7上,我收到此错误:

Traceback (most recent call last):
  File "c:\python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\Scripts\pip2.exe\__main__.py", line 5, in <module>
  File "c:\python27\lib\site-packages\pip\__init__.py", line 13, in <module>
    from pip.commands import commands, get_similar_commands, get_summaries
  File "c:\python27\lib\site-packages\pip\commands\__init__.py", line 6, in <module>
    from pip.commands.bundle import BundleCommand
  File "c:\python27\lib\site-packages\pip\commands\bundle.py", line 5, in <module>
    from pip.commands.install import InstallCommand
  File "c:\python27\lib\site-packages\pip\commands\install.py", line 5, in <module>
    from pip.req import InstallRequirement, RequirementSet, parse_requirements
  File "c:\python27\lib\site-packages\pip\req\__init__.py", line 3, in <module>
    from .req_install import InstallRequirement
  File "c:\python27\lib\site-packages\pip\req\req_install.py", line 20, in <module>
    import pip.wheel
  File "c:\python27\lib\site-packages\pip\wheel.py", line 27, in <module>
    from pip.download import path_to_url, unpack_url
ImportError: cannot import name unpack_url

我也试试这个:python2.7 -m pip install scikit-learnpython27 -m pip install scikit-learn 我收到这个错误:

python2.7 : The term 'python2.7' is not recognized as the name of a cmdlet,                  function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify   that the path is correct and try agai
At line:1 char:1
+ python2.7 -m pip install scikit-learn
+ ~~~~~~~~~
  + CategoryInfo          : ObjectNotFound: (python2.7:String) [],           CommandNotFoundException
  + FullyQualifiedErrorId : CommandNotFoundException

我在C:\Python27上有python 2.7 怎么办?

3 个答案:

答案 0 :(得分:1)

最安全且最不令人沮丧的方法是将独立的scikit学习副本加载到两个虚拟环境中。

按安装方式安装:

$ pip install virtualenv

$ pip install virtualenvwrapper

然后

$ mkvirtualenv --python=<path to python> <name virtualenv>

运行它......

workon <name virtualenv>

答案 1 :(得分:0)

在Windows上,您可以使用

for python2.x py -2 for python3.x py -3

所以它会是

py -2 -m pip install scikit-learn
py -3 -m pip install scikit-learn

只需尝试py --help了解更多信息

答案 2 :(得分:0)

感谢分配答案, 经过一番尝试和失败后,我找到了两种不同的方法来解决它 1。 <PATH-FOR-PYTHON>\scripts\pip.exe install <package name>

2。 py -2 -E-m pip install scikit-learn for v3.5 py -3 -E -m pip install scikit-learn for v2.7