[英]How to install Flask on Python3 using pip?
I want to try using Flask with Python3. 我想尝试使用Flask和Python3。 I've got Python 3.4 on Ubuntu 14.04, which supposedly ships with pip included.
我在Ubuntu 14.04上有Python 3.4,据说包含了pip。 So I tried
所以我试过了
pip3 install flask
this ends in: 这结束于:
Cleaning up...
Command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_kramer65/flask/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-i98xjzea-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_kramer65/flask
Storing debug log for failure in /tmp/tmpqc3b2nu5
So I tried importing it, but to no avail: 所以我尝试导入它,但无济于事:
kramer65@vps1:~/cxs$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
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'
I can of course download it and install using sudo python3 setup.py install
it that way, but I would rather do it "the standard way" so that things are easily and more standard to setup on production machines. 我当然可以下载它并使用
sudo python3 setup.py install
它,但我宁愿这样做“标准方式”,以便在生产机器上轻松,更标准地设置。
Does anybody know how I can import Flask with Python3 and pip? 有谁知道如何用Python3和pip导入Flask? All tips are welcome!
欢迎所有提示!
Error log is available in http://pastebin.com/hd6LyVFP 错误日志可在http://pastebin.com/hd6LyVFP中找到
You seem to have a permission issue. 您似乎有权限问题。 From the log you pasted to pastebin:
从您粘贴到pastebin的日志:
error: could not create '/usr/local/lib/python3.4/dist-packages/flask': Permission denied
This is because pip
will attempt to install the package globally unless you specify a certain installation location. 这是因为
pip
将尝试全局安装包,除非您指定某个安装位置。 If you want to install this globally you must use sudo
or install as a user with privileges. 如果要全局安装,则必须使用
sudo
或以具有权限的用户身份进行安装。
Try the following: 请尝试以下方法:
sudo pip3 install flask
Or specify to a certain dir: 或者指定某个目录:
pip install -t <path> flask
However, with the latter method you will have to always inject the path to sys.modules
so I suggest you just use sudo
if you can. 但是,使用后一种方法,您必须始终注入
sys.modules
的路径,所以我建议您只使用sudo
如果可以的话。
Or even more preferrably, use virtualenv
. 或者甚至更优选地,使用
virtualenv
。 Virtualenv allows you to very easily package your application for production because you can install only the packages you need and you've thus got automatic package isolation. Virtualenv允许您非常轻松地打包您的应用程序以进行生产,因为您只能安装所需的软件包,因此您可以自动进行软件包隔离。 Generating a
requirements.txt
is then as simple as pip freeze > requirements.txt
. 然后生成
requirements.txt
就像pip freeze > requirements.txt
一样简单。 Remeber that if you end using a virtualenv, you must not use sudo
to install packages as they will then be installed outside the virtualenv. 请记住,如果您使用virtualenv结束,则不得使用
sudo
来安装软件包,因为它们将安装在virtualenv之外。
对于Python 3.6.4版本,可以通过执行以下操作来安装Flask:
sudo pip3.6 install flask
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.