我按照本网页中给出的步骤安装了Flask,所以首先通过以下命令代码设置Python3的环境:
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.
>>> 到目前为止,这听起来还不错,然后我试着安装了水瓶,结果是这样的:
(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而不是Python2.7安装水瓶呢?
发布于 2018-10-08 09:22:44
您创建并激活了一个virtualenv,然后忽略了它,因为您使用了sudo
$ sudo pip install flask激活virtualenv只需设置PATH变量,以便在运行pip、python等时首先将命令放在bin目录中。
但是当您使用sudo时,您将创建一个在root用户下运行的新的子shell,然后有效地告诉操作系统不要使用当前的shell配置。并且在作为pip用户执行时发现的root命令与为您的虚拟用户设置的命令不同。
接下来,您将不希望将包作为root安装到您的虚拟环境中。将它们安装为当前用户。
简单地放下sudo
$ pip install flask甚至直接引用bin/pip命令:
$ bin/pip install flaskvirtualenv的全部目的是为您提供一个独立的Python环境,您可以根据需要添加和删除包,而不需要根访问。
https://stackoverflow.com/questions/52698767
复制相似问题