简体   繁体   English

Flask是为Python 2.7而非Python 3安装的

[英]Flask is installed for Python 2.7 and not for Python 3

I installed Flask following the steps given in this webpage , so first I set the enviroment for Python 3 by following command code: 我按照此网页中提供的步骤安装了Flask,因此首先我通过遵循以下命令代码来设置Python 3的环境:

pooja@X1-Carbon-6:~/Documents/sva/projekten$  python3 -m venv venv
pooja@X1-Carbon-6:~/Documents/sva/projekten$ . venv/bin/activate
(venv) pooja@X1-Carbon-6:~/Documents/sva/projekten$ python
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

which so far sounds good, then I tried to install Flask and this is what happens: 到目前为止听起来不错,然后我尝试安装Flask,结果是这样的:

(venv) pooja@X1-Carbon-6:~/Documents/sva/projekten$ sudo pip install flask
[sudo] password for pooja: 
The directory '/home/pooja/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/pooja/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting flask
  Downloading https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl (91kB)
    100% |████████████████████████████████| 92kB 836kB/s 
Requirement already satisfied: Jinja2>=2.10 in /usr/local/lib/python2.7/dist-packages (from flask) (2.10)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python2.7/dist-packages (from flask) (0.24)
Requirement already satisfied: Werkzeug>=0.14 in /usr/local/lib/python2.7/dist-packages (from flask) (0.14.1)
Requirement already satisfied: click>=5.1 in /usr/local/lib/python2.7/dist-packages (from flask) (7.0)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python2.7/dist-packages (from Jinja2>=2.10->flask) (1.0)
Installing collected packages: flask
Successfully installed flask-1.0.2
(venv) pooja@X1-Carbon-6:~/Documents/sva/projekten$ flask --version
Flask 1.0.2
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609]
(venv) pooja@X1-Carbon-6:~/Documents/sva/projekten$ 

Does anybody have any ideas, how can I install Flask for Python 3 and not for Python 2.7? 有人有什么想法吗,如何为Python 3(而非Python 2.7)安装Flask?

You created and activated a virtualenv, and then ignored it , because you used sudo : 您创建并激活了virtualenv, 然后忽略了它 ,因为您使用了sudo

$ sudo pip install flask

Activating a virtualenv simply sets the PATH variable to put the commands in the bin directory first when running pip , python , etc. 激活virtualenv只需将PATH变量设置为在运行pippython等时首先将命令放在bin目录中。

But when you use sudo , you create a new sub-shell running under the root user, and you then effectively tell the OS to not use the current shell configuration . 但是,当您使用sudo ,您将创建一个在root用户下运行的新子shell,然后有效地告诉OS 不要使用当前的shell配置 And the pip command found when executing as the root user is not the same command as the one set up for your virtualenv. 而且,以root用户身份执行时找到的pip命令与为virtualenv设置的命令不同。

Next, you would not want to install packages as root into your virtualenv anyway. 接下来,无论如何您都不想以root用户身份将软件包安装到virtualenv中。 Install them as the current user instead. 而是以当前用户身份安装它们。

Simply drop the sudo : 只需删除sudo

$ pip install flask

or even directly reference the bin/pip command: 甚至直接引用bin/pip命令:

$ bin/pip install flask

The whole point of a virtualenv is to give you an isolated Python environment that is your own, where you can add and remove packages as you need to, without needing root access. virtualenv的全部目的是为您提供一个独立的Python环境,您可以在其中添加和删除软件包,而无需root访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM