Flask CLI可执行文件未安装在Python 3中的预期位置

时间:2018-12-01 22:51:04

标签: python pip setuptools

我在Ubuntu 18.04计算机上,并且安装了python版本2.7和3.6。我首先在python 2.7中安装了flask:

$ sudo pip install flask
$ flask --version
Flask 1.0.2
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0]

但是由于我想在Python3中构建应用程序,因此我从python 2.7卸载了flask,并在python 3.6中安装了它:

$ sudo pip uninstall flask
$ sudo pip3 install flask
$ flask --version
bash: /usr/local/bin/flask: No such file or directory

即使它似乎已正确安装:

$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>> flask.__version__
'1.0.2'

有什么想法可以在Python 3中使用flask cli吗?

p.s .:我知道我可以使用virtualenv,但我想知道为什么会这样。

[编辑]

好,现在我在用户目录中看到了Python 3中的flask:

>>> import flask; print(flask)
<module 'flask' from '/home/kramer65/.local/lib/python3.6/site-packages/flask/__init__.py'>

如果我在Python 2.7中安装flask,那么它将在全局安装:

>>> import flask; print(flask)
<module 'flask' from '/usr/local/lib/python2.7/dist-packages/flask/__init__.pyc'>

为什么会有这种区别?有人知道我也可以在Python 3中全局安装flask吗?

[EDIT2]

作为@hoefling对问题的回答:

$ pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

[EDIT3]

结果全部都安装在我的~/.local/文件夹中。当我卸载然后再次重新安装flask时,我得到了这一点(也请注意其他库的位置路径):

$ sudo pip3 install flask
The directory '/home/kramer65/.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/kramer65/.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 1.6MB/s 
Requirement already satisfied: Werkzeug>=0.14 in /home/kramer65/.local/lib/python3.6/site-packages (from flask)
Requirement already satisfied: itsdangerous>=0.24 in /home/kramer65/.local/lib/python3.6/site-packages (from flask)
Requirement already satisfied: Jinja2>=2.10 in /home/kramer65/.local/lib/python3.6/site-packages (from flask)
Requirement already satisfied: click>=5.1 in /home/kramer65/.local/lib/python3.6/site-packages (from flask)
Requirement already satisfied: MarkupSafe>=0.23 in /home/kramer65/.local/lib/python3.6/site-packages (from Jinja2>=2.10->flask)
Installing collected packages: flask
Successfully installed flask-1.0.2

但是当我执行pip3 show flask时,它表示位置为/usr/local/lib/python3.6/dist-packages

$ pip3 show flask
Name: Flask
Version: 1.0.2
Summary: A simple framework for building complex web applications.
Home-page: https://www.palletsprojects.com/p/flask/
Author: Armin Ronacher
Author-email: armin.ronacher@active-4.com
License: BSD
Location: /usr/local/lib/python3.6/dist-packages
Requires: Werkzeug, Jinja2, click, itsdangerous

这是怎么回事?

0 个答案:

没有答案
相关问题