如何在python控制台中使用pip安装本地包

时间:2017-02-13 06:44:13

标签: python pip install local

我不确定这是因为我在公司工作并且有代理,我无法设置环境变量。所以,我不能在CMD中使用pip install。我尝试将软件包下载到我的本地计算机,并使用Installing python module within code中的方法进行安装。但我失败了。这是我的代码:

import pip
pip.main(['install','h://feng.officeworks/mixed/myPython/numpy-1.12.0'])

这对我不起作用,我有以下信息:

Invalid requirement: 'h://feng.officeworks/mixed/myPython/numpy'
Traceback (most recent call last):
  File "C:\Users\fchen4\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\packaging\requirements.py", line 92, in __init__
    req = REQUIREMENT.parseString(requirement_string)
  File "C:\Users\fchen4\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\pyparsing.py", line 1617, in parseString
    raise exc
  File "C:\Users\fchen4\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\pyparsing.py", line 1607, in parseString
    loc, tokens = self._parse( instring, 0 )
  File "C:\Users\fchen4\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\pyparsing.py", line 1379, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "C:\Users\fchen4\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\pyparsing.py", line 3376, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "C:\Users\fchen4\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\pyparsing.py", line 1383, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "C:\Users\fchen4\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\pyparsing.py", line 3164, in parseImpl
    raise ParseException(instring, loc, self.errmsg, self)
pip._vendor.pyparsing.ParseException: Expected stringEnd (at char 1), (line:1, col:2)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\fchen4\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\req\req_install.py", line 82, in __init__
    req = Requirement(req)
  File "C:\Users\fchen4\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pip\_vendor\packaging\requirements.py", line 96, in __init__
requirement_string[e.loc:e.loc + 8]))
pip._vendor.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at "'://feng.'"
1

我使用的是Windows 10,Python 3.6.0,Pycharm 2016.3.2。 pip已经安装了Python

另外,因为我无法访问环境变量,所以无法设置Python的路径。所以我不能在窗口终端中使用像python或pip这样的命令。所以我需要在python控制台中使用一个函数。

非常感谢你的回答。我还试着去C:\ Users \ fchen4 \ AppData \ Local \ Programs \ Python \ Python36-32 \ Scripts,然后使用

pip install h://mypath/numpy. 

我已经在这里解开numpy了。这是行不通的。 PowerShell中显示的信息如下:

Obtaining file:///H:/feng.officeworks/mixed/myPython/numpy
Installing collected packages: numpy
  Running setup.py develop for numpy
    Complete output from command c:\users\fchen4\appdata\local\programs\python\python36-32\python.exe -c "import setuptools, tokenize;__file__='H:\\feng.officeworks\\mixed\\m
yPython\\numpy\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" develop --no-deps:
    blas_opt_info:
    blas_mkl_info:
      libraries mkl_rt not found in ['c:\\users\\fchen4\\appdata\\local\\programs\\python\\python36-32\\lib', 'C:\\', 'c:\\users\\fchen4\\appdata\\local\\programs\\python\\py
thon36-32\\libs']
      NOT AVAILABLE

    .... (There are too much here so I ignore it.)
    ....
Command "c:\users\fchen4\appdata\local\programs\python\python36-32\python.exe -c "import setuptools, tokenize;__file__='H:\\feng.officeworks\\mixed\\myPython\\numpy\\setup.py
';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" develop --no-deps" failed with error code 1
 in H:\feng.officeworks\mixed\myPython\numpy\

任何人都可以告诉我如何在python控制台中使用pip或其他任何东西安装本地软件包?

1 个答案:

答案 0 :(得分:0)

安装特定的源存档文件:

pip install ./downloads/SomePackage-1.0.4.tar.gz

您也可以下载模块源代码并安装它,将存档解压缩到名称相同的目录:foo-1.0。此外,分发将包含安装脚本setup.py,然后从终端运行此命令:

python setup.py install

如果您想在代码中安装软件包,请尝试以下方法:

import os
os.system("pip2.7 install foo")

import subprocess
subprocess.call(['pip', 'install', foo])

希望这有帮助。