从git bash运行flask应用程序时,tensorflow出现问题

时间:2019-02-04 20:25:44

标签: python git tensorflow flask

我已经在anaconda环境中安装了tensorflow。在spyder中工作正常。但是,当我尝试从git终端启动Flask服务器时,它显示的是:

Admin@DESKTOP-SST22ME MINGW64 /d/doodle classifier
$ export FLASK_APP=app.py

Admin@DESKTOP-SST22ME MINGW64 /d/doodle classifier
$ flask run
 * Serving Flask app "app.py"
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
Using TensorFlow backend.
Usage: flask run [OPTIONS]

Error: While importing "app", an ImportError was raised:

Traceback (most recent call last):
  File "d:\python\lib\site-packages\flask\cli.py", line 235, in locate_app
    __import__(module_name)
  File "D:\doodle classifier\app.py", line 5, in <module>
    import keras
  File "d:\python\lib\site-packages\keras\__init__.py", line 3, in <module>
    from . import utils
  File "d:\python\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
    from . import conv_utils
  File "d:\python\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "d:\python\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
    from .tensorflow_backend import *
  File "d:\python\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'

我试图从git终端安装tensorflow,但显示如下:

Admin@DESKTOP-SST22ME MINGW64 /d/doodle classifier
$ conda install tensorflow
Solving environment: ...working... done

## Package Plan ##

  environment location: C:\Users\Admin\Anaconda3

  added / updated specs:
    - tensorflow


The following NEW packages will be INSTALLED:

    _tflow_select:       2.2.0-eigen
    absl-py:             0.7.0-py36_0
    astor:               0.7.1-py36_0
    gast:                0.2.2-py36_0
    grpcio:              1.16.1-py36h351948d_1
    icc_rt:              2019.0.0-h0cc432a_1
    keras-applications:  1.0.6-py36_0
    keras-preprocessing: 1.0.5-py36_0
    libprotobuf:         3.6.1-h7bd577a_0
    markdown:            3.0.1-py36_0
    protobuf:            3.6.1-py36h33f27b4_0
    pyreadline:          2.1-py36_1
    pysocks:             1.6.8-py36_0
    tensorboard:         1.12.2-py36h33f27b4_0
    tensorflow:          1.12.0-eigen_py36h67ac661_0
    tensorflow-base:     1.12.0-eigen_py36h45df0d8_0
    termcolor:           1.1.0-py36_1
    urllib3:             1.24.1-py36_0
    win_inet_pton:       1.0.1-py36_1

The following packages will be UPDATED:

    astropy:             1.3.2-np112py36_0                       --> 2.0.11-py36h8c2d366_0
    bottleneck:          1.2.1-np112py36_0                       --> 1.2.1-py36h452e1ab_1
    ca-certificates:     2018.11.29-ha4d7672_0       conda-forge --> 2018.12.5-0
    conda:               4.5.12-py36_1000            conda-forge --> 4.6.2-py36_0
    cryptography:        2.3.1-py36h74b6da3_1000     conda-forge --> 2.4.2-py36h7a1dbc1_0
    h5py:                2.7.0-np112py36_0                       --> 2.9.0-py36h5e291fa_0
    hdf5:                1.8.15.1-vc14_4                         --> 1.10.4-h7ebc959_0
    llvmlite:            0.18.0-py36_0                           --> 0.27.0-py36ha925a31_0
    menuinst:            1.4.7-py36_0                            --> 1.4.14-py36hfa6e2cd_0
    numba:               0.33.0-np112py36_0                      --> 0.42.0-py36hf9181ef_0
    numexpr:             2.6.2-np112py36_0                       --> 2.6.2-np113py36_0
    numpy:               1.12.1-py36_0                           --> 1.13.3-py36hb69e940_3
    openssl:             1.0.2p-hfa6e2cd_1002        conda-forge --> 1.1.1a-he774522_0
    pandas:              0.20.1-np112py36_0                      --> 0.24.0-py36ha925a31_0
    pyqt:                5.6.0-py36_2                            --> 5.9.2-py36h6538335_2
    pywavelets:          0.5.2-np112py36_0                       --> 1.0.1-py36h8c2d366_0
    qt:                  5.6.2-h2639256_8            conda-forge --> 5.9.7-vc14h73c81de_0
    requests:            2.14.2-py36_0                           --> 2.21.0-py36_0
    scikit-learn:        0.18.1-np112py36_1                      --> 0.19.0-np113py36_0
    scipy:               0.19.0-np112py36_0                      --> 0.19.1-np113py36_0
    sip:                 4.18-py36_0                             --> 4.19.8-py36h6538335_0
    statsmodels:         0.8.0-np112py36_0                       --> 0.9.0-py36h452e1ab_0

The following packages will be DOWNGRADED:

    certifi:             2018.11.29-py36_1000        conda-forge --> 2018.11.29-py36_0
    opencv:              3.4.4-py36hb76ac4c_1203     conda-forge --> 3.3.1-py36h20b85fd_1

Proceed ([y]/n)? y

Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... failed
ERROR conda.core.link:_execute(507): An error occurred while installing package 'defaults::icc_                                     rt-2019.0.0-h0cc432a_1'.
PermissionError(13, 'Permission denied')
Attempting to roll back.

Rolling back transaction: ...working... done

PermissionError(13, 'Permission denied')

我该怎么办?我应该卸载anaconda然后尝试重新安装它吗?如果还有其他更好的方式来运行flask应用,请同时提及它们。

编辑:我想提到几个月前我从anaconda提示符下安装了tensorflow。如果我在anaconda中键入pip install tensorflow,则提示其显示:

(base) C:\Users\Admin>pip install tensorflow
Requirement already satisfied: tensorflow in c:\users\admin\anaconda3\lib\site-packages (1.12.0)
Requirement already satisfied: numpy>=1.13.3 in c:\users\admin\anaconda3\lib\site-packages (from tensorflow) (1.15.1)
Requirement already satisfied: wheel>=0.26 in c:\users\admin\anaconda3\lib\site-packages (from tensorflow) (0.32.3)
Requirement already satisfied: six>=1.10.0 in c:\users\admin\anaconda3\lib\site-packages (from tensorflow) (1.11.0)
Requirement already satisfied: protobuf>=3.6.1 in c:\users\admin\anaconda3\lib\site-packages (from tensorflow) (3.6.1)
Requirement already satisfied: tensorboard<1.13.0,>=1.12.0 in c:\users\admin\anaconda3\lib\site-packages (from tensorflow) (1.12.1)
Requirement already satisfied: termcolor>=1.1.0 in c:\users\admin\anaconda3\lib\site-packages (from tensorflow) (1.1.0)
Requirement already satisfied: keras-preprocessing>=1.0.5 in c:\users\admin\anaconda3\lib\site-packages (from tensorflow) (1.0.5)
Requirement already satisfied: astor>=0.6.0 in c:\users\admin\anaconda3\lib\site-packages (from tensorflow) (0.7.1)
Requirement already satisfied: keras-applications>=1.0.6 in c:\users\admin\anaconda3\lib\site-packages (from tensorflow) (1.0.6)
Requirement already satisfied: absl-py>=0.1.6 in c:\users\admin\anaconda3\lib\site-packages (from tensorflow) (0.6.1)
Requirement already satisfied: grpcio>=1.8.6 in c:\users\admin\anaconda3\lib\site-packages (from tensorflow) (1.17.1)
Requirement already satisfied: gast>=0.2.0 in c:\users\admin\anaconda3\lib\site-packages (from tensorflow) (0.2.0)
Requirement already satisfied: setuptools in c:\users\admin\anaconda3\lib\site-packages (from protobuf>=3.6.1->tensorflow) (40.6.3)
Requirement already satisfied: markdown>=2.6.8 in c:\users\admin\anaconda3\lib\site-packages (from tensorboard<1.13.0,>=1.12.0->tensorflow) (3.0.1)
Requirement already satisfied: werkzeug>=0.11.10 in c:\users\admin\anaconda3\lib\site-packages (from tensorboard<1.13.0,>=1.12.0->tensorflow) (0.14.1)
Requirement already satisfied: h5py in c:\users\admin\anaconda3\lib\site-packages (from keras-applications>=1.0.6->tensorflow) (2.8.0)

1 个答案:

答案 0 :(得分:0)

您是否尝试过如下所示安装它:-

pip3.7 install tensorflow --user

pip3 install tensorflow --user