简体   繁体   English

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

[英]install 'pip' package for specific version of Python on Windows

I have on my machine (windows 10) two versions of python: 3.5 2.7 我的机器上(Windows 10)有两个版本的python:3.5 2.7
I need to install a package using pip but I want the package on both. 我需要使用pip安装程序包,但我都想同时使用该程序包。

My default version is 3.5. 我的默认版本是3.5。

I try to do this: pip2 install scikit-learn to install it on python 2.7 and I get this error: 我尝试这样做: 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

I also try this: python2.7 -m pip install scikit-learn or python27 -m pip install scikit-learn and I get this error: 我也尝试这样做: 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

I do have python 2.7 on C:\\Python27 . 我在C:\\Python27上确实有python 2.7。
What to do? 该怎么办?

The safest and least frustrating way to go about this is to load independent copies of scikit learn into two virtual environments. 进行此操作最安全,最无忧的方法是将scikit学习的独立副本加载到两个虚拟环境中。

Install by: 安装方式:

$ pip install virtualenv

$ pip install virtualenvwrapper

Then 然后

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

To run it... 要运行它...

workon <name virtualenv>

On Windows you can use 在Windows上,您可以使用

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

so it would be 所以会是

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

just try py --help for more info 只需尝试py --help了解更多信息

Thanks allot for the answers, after some try&fail I find 2 different ways to figure it. 感谢分配的答案,经过一番尝试后,我发现了两种不同的方法来解决它。
1. <PATH-FOR-PYTHON>\\scripts\\pip.exe install <package name> 1. <PATH-FOR-PYTHON>\\scripts\\pip.exe install <package name>

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

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

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