关于错误安装Flask:错误安装Flask-Python

Error installing Flask - Python

我仍在尝试在"虚拟环境"上安装Flask。 激活virtualenv时,尝试获取pip命令时出现一些错误。 (需要做的事情是我的用户名名称中有空格)
但最后找到了解决方案,只需输入正确的pip路径即可,以避开用户名文件夹。

1
2
3
4
5
6
7
(venv) C:\Users\Daniel P-C>cd C:\Python34\Scripts

(venv) C:\Python34\Scripts>pip

 Usage:
      pip <command> [options]
 etc...

很好,当尝试安装flask时出现以下错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
(venv) C:\Python34\Scripts>pip install flask
Downloading/unpacking flask
  Running setup.py (path:C:\Users\DANIEL~1\AppData\Local\Temp\pip_build_Daniel P
-C\flask\setup.py) egg_info for package flask

    warning: no files found matching '*' under directory 'tests'
    warning: no previously-included files matching '*.pyc' found under directory
 'docs'
    warning: no previously-included files matching '*.pyo' found under directory
 'docs'
    warning: no previously-included files matching '*.pyc' found under directory
 'tests'
    warning: no previously-included files matching '*.pyo' found under directory
 'tests'
    warning: no previously-included files matching '*.pyc' found under directory
 'examples'
    warning: no previously-included files matching '*.pyo' found under directory
 'examples'
    no previously-included directories found matching 'docs\_build'
    no previously-included directories found matching 'docs\_themes\.git'
Downloading/unpacking Werkzeug>=0.7 (from flask)
  Running setup.py (path:C:\Users\DANIEL~1\AppData\Local\Temp\pip_build_Daniel P
-C\Werkzeug\setup.py) egg_info for package Werkzeug

    warning: no files found matching '*' under directory 'werkzeug\debug\templat
es'

    warning: no files found matching '*' under directory 'tests'
    warning: no previously-included files matching '*.pyc' found under directory
 'docs'
    warning: no previously-included files matching '*.pyo' found under directory
 'docs'
    warning: no previously-included files matching '*.pyc' found under directory
 'tests'
    warning: no previously-included files matching '*.pyo' found under directory
 'tests'
    warning: no previously-included files matching '*.pyc' found under directory
 'examples'
    warning: no previously-included files matching '*.pyo' found under directory
 'examples'
    no previously-included directories found matching 'docs\_build'
Downloading/unpacking Jinja2>=2.4 (from flask)
  Running setup.py (path:C:\Users\DANIEL~1\AppData\Local\Temp\pip_build_Daniel P
-C\Jinja2\setup.py) egg_info for package Jinja2

    warning: no files found matching '*' under directory 'custom_fixers'
    warning: no previously-included files matching '*' found under directory 'do
cs\_build'

    warning: no previously-included files matching '*.pyc' found under directory
 'jinja2'
    warning: no previously-included files matching '*.pyc' found under directory
 'docs'
    warning: no previously-included files matching '*.pyo' found under directory
 'jinja2'
    warning: no previously-included files matching '*.pyo' found under directory
 'docs'
Downloading/unpacking itsdangerous>=0.21 (from flask)
  Running setup.py (path:C:\Users\DANIEL~1\AppData\Local\Temp\pip_build_Daniel P
-C\itsdangerous\setup.py) egg_info for package itsdangerous

    warning: no previously-included files matching '*' found under directory 'do
cs\_build'

Downloading/unpacking markupsafe (from Jinja2>=2.4->flask)
  Downloading MarkupSafe-0.23.tar.gz
  Running setup.py (path:C:\Users\DANIEL~1\AppData\Local\Temp\pip_build_Daniel P
-C\markupsafe\setup.py) egg_info for package markupsafe

Installing collected packages: flask, Werkzeug, Jinja2, itsdangerous, markupsafe

  Running setup.py install for flask

    warning: no files found matching '*' under directory 'tests'
    warning: no previously-included files matching '*.pyc' found under directory
 'docs'
    warning: no previously-included files matching '*.pyo' found under directory
 'docs'
    warning: no previously-included files matching '*.pyc' found under directory
 'tests'
    warning: no previously-included files matching '*.pyo' found under directory
 'tests'
    warning: no previously-included files matching '*.pyc' found under directory
 'examples'
    warning: no previously-included files matching '*.pyo' found under directory
 'examples'
    no previously-included directories found matching 'docs\_build'
    no previously-included directories found matching 'docs\_themes\.git'
  Running setup.py install for Werkzeug

    warning: no files found matching '*' under directory 'werkzeug\debug\templat
es'

    warning: no files found matching '*' under directory 'tests'
    warning: no previously-included files matching '*.pyc' found under directory
 'docs'
    warning: no previously-included files matching '*.pyo' found under directory
 'docs'
    warning: no previously-included files matching '*.pyc' found under directory
 'tests'
    warning: no previously-included files matching '*.pyo' found under directory
 'tests'
    warning: no previously-included files matching '*.pyc' found under directory
 'examples'
    warning: no previously-included files matching '*.pyo' found under directory
 'examples'
    no previously-included directories found matching 'docs\_build'
  Running setup.py install for Jinja2

    warning: no files found matching '*' under directory 'custom_fixers'
    warning: no previously-included files matching '*' found under directory 'do
cs\_build'

    warning: no previously-included files matching '*.pyc' found under directory
 'jinja2'
    warning: no previously-included files matching '*.pyc' found under directory
 'docs'
    warning: no previously-included files matching '*.pyo' found under directory
 'jinja2'
    warning: no previously-included files matching '*.pyo' found under directory
 'docs'
  Running setup.py install for itsdangerous

    warning: no previously-included files matching '*' found under directory 'do
cs\_build'

  Running setup.py install for markupsafe

    building 'markupsafe._speedups' extension
    ==========================================================================
    WARNING: The C extension could not be compiled, speedups are not enabled.
    Failure information, if any, is above.
    Retrying the build without the C extension now.


    ==========================================================================
    WARNING: The C extension could not be compiled, speedups are not enabled.
    Plain-Python installation succeeded.
    ==========================================================================
Successfully installed flask Werkzeug Jinja2 itsdangerous markupsafe
Cleaning up...

它说它已经成功安装了flask,但是在运行python并尝试键入import flask时,好像没有安装? 我能做什么?

1
2
3
4
5
6
7
8
(venv) C:\Python34\Scripts>python
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (In
tel)] on win32
Type"help","copyright","credits" or"license" for more information.
>>> import flask
Traceback (most recent call last):
  File"<stdin>", line 1, in <module>
ImportError: No module named 'flask'

我正在Windows 7上运行


确保使用venv的pip和python

要使pip将模块/软件包安装到virtualenv,必须使用virtualenv中的pip

要将要安装的模块/软件包导入virtualenv环境,您必须从给定的virtualenv中运行python解释器。

如果您从目录C:\Python 34\Scripts运行pippython,则很有可能使用系统范围的pip并将flask安装到系统Python中。在Linux上,您会遇到问题,因为安装到系统范围内的python需要root特权,而在MS Windows上,默认Python安装不会出错。

建议:在默认的Python安装目录之外创建您的virtualenv,并使用此virtulaenv中的pippython。激活virtualenv时通常会发生这种情况,因此无需显式使用pippython的完整路径(无论如何,使用显式的venv pythonpip路径不会对您造成任何损害。


我遇到了与您完全相同的问题,而Jan的答案对我没有用。

问题很简单,我使用apt-get安装了virtualenv:

1
$ sudo apt-get install virtualenv

而不是通过pip安装它:

1
2
3
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ sudo python get-pip.py
$ sudo pip install virtualenv

它为我解决了问题。您甚至可以在以下情况下卸载apt-get软件包:

1
$ sudo apt-get remove virtualenv

virtualenv仍已安装(但不错!)。


您是否在路径中添加了python?

尝试这个:

  • 点击开始
  • 搜索高级系统设置,然后单击
  • 单击环境变量。
  • 将; C: python27附加到Path变量
  • 重新启动命令提示符。