Flask 是为 Python 2.7 而不是 Python 3 安装的
Flask is installed for Python 2.7 and not for Python 3
我按照 this webpage 中给出的步骤安装了 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.
>>>
到目前为止听起来不错,然后我尝试安装 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$
有没有人有任何想法,我如何为 Python 3 安装 Flask 而不是 Python 2.7?
您创建并激活了一个 virtualenv,然后忽略了它,因为您使用了 sudo
:
$ sudo pip install flask
激活 virtualenv 只需设置 PATH
变量,以便在 运行 pip
、python
等时首先将命令放在 bin
目录中。
但是当你使用sudo
时,你在root
用户下创建了一个新的子shell运行,然后你有效地告诉了OS 不使用当前 shell 配置 。并且 pip
命令发现 作为 root
用户执行时 与为您的 virtualenv 设置的命令不同。
接下来,无论如何您都不想将包作为 root 安装到您的 virtualenv 中。改为以当前用户身份安装它们。
只需删除 sudo
:
$ pip install flask
甚至直接引用 bin/pip
命令:
$ bin/pip install flask
virtualenv 的全部意义在于为您提供一个属于您自己的隔离 Python 环境,您可以在其中根据需要添加和删除包,而无需 root 访问权限。
我按照 this webpage 中给出的步骤安装了 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.
>>>
到目前为止听起来不错,然后我尝试安装 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$
有没有人有任何想法,我如何为 Python 3 安装 Flask 而不是 Python 2.7?
您创建并激活了一个 virtualenv,然后忽略了它,因为您使用了 sudo
:
$ sudo pip install flask
激活 virtualenv 只需设置 PATH
变量,以便在 运行 pip
、python
等时首先将命令放在 bin
目录中。
但是当你使用sudo
时,你在root
用户下创建了一个新的子shell运行,然后你有效地告诉了OS 不使用当前 shell 配置 。并且 pip
命令发现 作为 root
用户执行时 与为您的 virtualenv 设置的命令不同。
接下来,无论如何您都不想将包作为 root 安装到您的 virtualenv 中。改为以当前用户身份安装它们。
只需删除 sudo
:
$ pip install flask
甚至直接引用 bin/pip
命令:
$ bin/pip install flask
virtualenv 的全部意义在于为您提供一个属于您自己的隔离 Python 环境,您可以在其中根据需要添加和删除包,而无需 root 访问权限。