我在Windows机器上使用python 2.7。我可以使用pip install安装flask,如下所示:
但是,在我创建了virtualenv后,我在尝试做同样的事情时得到了以下错误。
脚本:
$pip install virtualenv
$cd /d d:
$mkdir test
$cd test
$virtualenv flaskEnv
$cd flaskEnv/Scritps/
$activate
$cd ../../
$pip install flask
日志文件如下:
Collecting flask
Using cached Flask-0.11.1-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): click>=2.0 in c:\projects\flask-react\flsk\lib\site-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): Werkzeug>=0.7 in c:\projects\flask-react\flsk\lib\site-packages (from flask)
Collecting Jinja2>=2.4 (from flask)
Using cached Jinja2-2.8-py2.py3-none-any.whl
Collecting itsdangerous>=0.21 (from flask)
Collecting MarkupSafe (from Jinja2>=2.4->flask)
Using cached MarkupSafe-0.23.tar.gz
Building wheels for collected packages: MarkupSafe
Running setup.py bdist_wheel for MarkupSafe: started
Running setup.py bdist_wheel for MarkupSafe: finished with status 'error'
Complete output from command c:\projects\flask-react\flsk\scripts\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\admini~1\\appdata\\local\\temp\\pip-build-3ep417\\MarkupSafe\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d c:\users\admini~1\appdata\local\temp\tmp8mkr70pip-wheel- --python-tag cp27:
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win32-2.7
creating build\lib.win32-2.7\markupsafe
copying markupsafe\tests.py -> build\lib.win32-2.7\markupsafe
copying markupsafe\_compat.py -> build\lib.win32-2.7\markupsafe
copying markupsafe\_constants.py -> build\lib.win32-2.7\markupsafe
copying markupsafe\_native.py -> build\lib.win32-2.7\markupsafe
copying markupsafe\__init__.py -> build\lib.win32-2.7\markupsafe
running egg_info
writing MarkupSafe.egg-info\PKG-INFO
writing top-level names to MarkupSafe.egg-info\top_level.txt
writing dependency_links to MarkupSafe.egg-info\dependency_links.txt
warning: manifest_maker: standard file '-c' not found
reading manifest file 'MarkupSafe.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'MarkupSafe.egg-info\SOURCES.txt'
copying markupsafe\_speedups.c -> build\lib.win32-2.7\markupsafe
running build_ext
building 'markupsafe._speedups' extension
error: [Error 2] The system cannot find the file specified
----------------------------------------
Running setup.py clean for MarkupSafe
Failed to build MarkupSafe
Installing collected packages: MarkupSafe, Jinja2, itsdangerous, flask
Running setup.py install for MarkupSafe: started
Running setup.py install for MarkupSafe: finished with status 'error'
Complete output from command c:\projects\flask-react\flsk\scripts\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\admini~1\\appdata\\local\\temp\\pip-build-3ep417\\MarkupSafe\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\admini~1\appdata\local\temp\pip-8v3_ep-record\install-record.txt --single-version-externally-managed --compile --install-headers c:\projects\flask-react\flsk\include\site\python2.7\MarkupSafe:
running install
running build
running build_py
creating build
creating build\lib.win32-2.7
creating build\lib.win32-2.7\markupsafe
copying markupsafe\tests.py -> build\lib.win32-2.7\markupsafe
copying markupsafe\_compat.py -> build\lib.win32-2.7\markupsafe
copying markupsafe\_constants.py -> build\lib.win32-2.7\markupsafe
copying markupsafe\_native.py -> build\lib.win32-2.7\markupsafe
copying markupsafe\__init__.py -> build\lib.win32-2.7\markupsafe
running egg_info
writing MarkupSafe.egg-info\PKG-INFO
writing top-level names to MarkupSafe.egg-info\top_level.txt
writing dependency_links to MarkupSafe.egg-info\dependency_links.txt
warning: manifest_maker: standard file '-c' not found
reading manifest file 'MarkupSafe.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'MarkupSafe.egg-info\SOURCES.txt'
copying markupsafe\_speedups.c -> build\lib.win32-2.7\markupsafe
running build_ext
building 'markupsafe._speedups' extension
error: [Error 2] The system cannot find the file specified
错误消息对任何人都有意义吗? 感谢
答案 0 :(得分:17)
此问题似乎与virtualenv中安装的setuptools版本有关。降级到旧版本为我修复了它。
来自你的virtualenv:
pip install setuptools==21.2.1
pip install flask
答案 1 :(得分:6)
昨天我遇到了这个问题。我通过下载MarkupSafe wheel并使用pip安装解决了这个问题。问题在于我的头脑。关于生成Speedups文件时出现错误的编译器标志,我认为。
1)从上面的链接下载车轮。
2)在Windows上,打开与滚轮相同目录中的命令窗口。
3)运行" pip Install"
答案 2 :(得分:2)
对于没有C编译器的系统上的Win7,MarkupSafe的setup.py被破坏了。 (我为VC ++工作保留了一个单独的VM)我这样做是为了让它工作:
pip download MarkupSafe
mkdir temp
open MarkupSafe-0.23.tar.gz with 7-zip, extract all to temp
cd temp
edit setup.py line 119 to read: if 0: #not (is_pypy or is_jython):
python setup.py install
我没有尝试调试setup.py以正常工作。我只想尝试Flask,因为它应该是轻量级且易于学习的,并且官方文档说它安装在Windows上。也许我应该回到Perl ......
与其他海报不同,MarkupSafe的全球点播安装对我来说也不起作用。
这些链接有关于此问题的其他观点/见解: https://github.com/pallets/markupsafe/issues/26 https://github.com/babun/babun/issues/315
答案 3 :(得分:1)
确定。我明白了。我不认为我安装烧瓶的方式有任何问题,正如我在我的问题中已经提到的,我能够在全球范围内安装它(无需在virtualenv中运行)。 MarkupSafe包有一个使用c实现的扩展,我没有在我的本地机器上安装windows sdk,所以当ve_build_ext运行时, ****它总是失败**
区别在于,如果不是(is_pypy或is_jython),它会发出警告,这是我在全局安装时得到的;但是,当它在virtualenv下运行时崩溃了。所以我很确定hasattr(sys,'pypy_version_info')在virtualenv下运行时返回true。
有没有人知道“hasattr(sys,'pypy_version_info')是什么意思?
# fail safe compilation shamelessly stolen from the simplejson
# setup.py file. Original author: Bob Ippolito
is_jython = 'java' in sys.platform
is_pypy = hasattr(sys, 'pypy_version_info')
def run_setup(with_binary):
ext = Extension('markupsafe._speedups', ['markupsafe/_speedups.c'])
ext_modules = [ext] if with_binary else []
def try_building_extension():
try:
run_setup(True)
except BuildFailed:
LINE = '=' * 74
BUILD_EXT_WARNING = 'WARNING: The C extension could not be ' \
'compiled, speedups are not enabled.'
echo(LINE)
echo(BUILD_EXT_WARNING)
echo('Failure information, if any, is above.')
echo('Retrying the build without the C extension now.')
echo()
run_setup(False)
echo(LINE)
echo(BUILD_EXT_WARNING)
echo('Plain-Python installation succeeded.')
echo(LINE)
如果不是(is_pypy或is_jython): try_building_extension() 其他: run_setup(假)
答案 4 :(得分:1)
我今天遇到了这个问题,并且根据林肯的建议,可以通过从MarkupSafe文件手动安装wheel来解决此问题。您可以下载相应的文件here。有几个可用。我不知道它们之间的区别是什么,但是唯一一个甚至可以安装在Windows 10上的是MarkupSafe-0.23-cp27-none-win32.whl。下载后,我将其复制到我使用virtualenv创建的目录中(不确定是否有必要,但这就是我所做的)并使用pip安装它:
C:\flask-test\venv>pip install MarkupSafe-0.23-cp27-none-win32.whl
从该目录。之后我回到主目录并安装了Flask
C:\flask-test\venv>cd ..
C:\flask-test>pip install Flask
它工作正常。