我仍在尝试在虚拟环境中安装Flask'。当virtualenv被激活时,我尝试获取pip命令时遇到了一些错误。 (有事情要做,我的用户名在名称中有空格) 但最终找到了解决方案,只需键入pip所在位置的正确路径,以避免使用username文件夹。
(venv) C:\Users\Daniel P-C>cd C:\Python34\Scripts
(venv) C:\Python34\Scripts>pip
Usage:
pip <command> [options]
etc...
当试图安装烧瓶时,我得到以下错误
(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...
它说它已经成功安装了烧瓶,但是当运行python并尝试输入导入烧瓶时,它就像是没有安装?我该怎么办?
(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
答案 0 :(得分:2)
要将pip
安装到virtualenv中的模块/包,您必须使用virtualenv中的pip
。
要将正在安装的模块/包导入virtualenv环境,您必须从给定的virtualenv运行python
解释器。
如果您从目录pip
运行python
或C:\Python 34\Scripts
,则很可能使用系统范围pip
并安装flask
系统Python。在Linux上你会遇到问题,因为安装到系统范围的python需要root权限,在MS Windows默认的Python安装上它不会抱怨。
建议:使用默认的Python安装目录创建virtualenv,并使用此virtulaenv中的pip
和python
。当您激活virtualenv时,通常会发生这种情况,因此无需明确使用pip
或python
的完整路径(无论如何,使用显式路径到venv python
和{{ 1}}不会伤害任何东西。
答案 1 :(得分:1)
我和你有完全相同的问题,Jan的答案对我不起作用。
问题在于我使用apt-get:
安装了virtualenv$ sudo apt-get install virtualenv
而不是用pip安装它:
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ sudo python get-pip.py
$ sudo pip install virtualenv
它解决了我的问题。您甚至可以在以下时间之后卸载apt-get软件包:
$ sudo apt-get remove virtualenv
virtualenv
仍然安装(但是好的!)。
答案 2 :(得分:-2)
您是否在路径中添加了python?
试试这个: