PIP软件包安装失败

时间:2019-02-12 18:07:55

标签: python-3.x pip

我尝试通过python代码安装丢失的软件包,如下所示。

try:
    from pip import main as pipmain
except ImportError:
    from pip._internal import main as pipmain

try:
    from flask import Flask, request, jsonify
except ImportError:
    pipmain(['install', 'flask', '--no-cache-dir'])

try:
    from flask_cors import CORS, cross_origin
except ImportError:
    pipmain(['install', 'flask-cors', '--no-cache-dir'])

try:
    from pony.orm import *
except ImportError:
    pipmain(['install', 'pony', '--no-cache-dir'])

try:
    import psycopg2
except ImportError:
    pipmain(['install', 'psycopg2', '--no-cache-dir'])

第一个软件包已成功安装。但是,在安装其他软件包时,会出现以下错误。

Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 
'C:\\Users\\mahyar\\AppData\\Local\\Temp\\pip-req-tracker-4k0r0y0l\\0a7b803e3382957ae56f10405258ccfa40023569f7a352a5aad0f489'

有解决方案吗?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我更改了代码,如下所示:

try:
    from pip import main as pipmain
except ImportError:
    from pip._internal import main as pipmain

try:
    from flask import Flask, request, jsonify
    from flask_cors import CORS, cross_origin
    from pony.orm import *
    import psycopg2
except ImportError:
    pipmain(['install', 'flask', 'pony', 'flask-cors', 'psycopg2'])

效果很好!