安装烧瓶; python脚本仍然无法导入

时间:2014-07-09 14:55:44

标签: python flask virtualenv

我尝试安装烧瓶时尝试了每一个命令行。我已按照http://flask.pocoo.org/docs/installation/

的说明进行操作

sudo easy_install virtualenv之后:

Searching for virtualenv
Best match: virtualenv 1.11.6
Adding virtualenv 1.11.6 to easy-install.pth file
Installing virtualenv script to /usr/local/bin
Installing virtualenv-2.7 script to /usr/local/bin

Using /usr/local/lib/python2.7/dist-packages
Processing dependencies for virtualenv
Finished processing dependencies for virtualenv
pip-install flask之后

Requirement already satisfied (use --upgrade to upgrade): flask in ./python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): Werkzeug>=0.7 in ./python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in ./python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): itsdangerous>=0.21 in ./python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): markupsafe in ./python2.7/dist-packages (from Jinja2>=2.4->flask)
Cleaning up...

但是在. venv/bin/activate之后:

bash: venv/bin/activate: No such file or directory

我知道如何浏览终端并创建目录。我不确定如何处理此命令和/或激活virtualenv。我找不到这个目录,或者sudo / pip命令可能是针对我的驱动器上没有默认的目录?

我尝试使用flask运行python脚本,当然:

Traceback (most recent call last):
  File "testingflask.py", line 1, in <module>
    from flask import Flask
ImportError: No module named flask

这是脚本: testingflask.py

from flask import flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

我也试过了apt-get install python-flask

3 个答案:

答案 0 :(得分:1)

你做过

吗?
$ mkdir myproject
$ cd myproject
$ virtualenv venv

步骤? (显然不是)

在任何情况下,你应该在激活virutualenv之后执行pip install Flask。否则它将安装在你的基础python安装中。

另外请注意,python区分大小写:

from flask import Flask
app = Flask(__name__)

答案 1 :(得分:0)

你运行virtualenv venv了吗?我的意思是你的项目中有venv个文件夹吗? 我猜你错过了这一步!

  1. $ sudo easy_install virtualenvsudo easy_install virtualenv
  2. $ mkdir myproject
  3. $ cd myproject
  4. virtualenv venv
  5. 我按照这些步骤操作,venv中应该有一个myproject目录,$ . venv/bin/activate命令可以正常工作

答案 2 :(得分:0)

还有一件事要尝试

  • 了解存储site-packages的python路径
  • 下载flask module并将其解压缩
  • 复制解压缩的文件夹并将其粘贴到python包目录中(主要是 site-packages / dist-packages for me :/usr/lib/python2.7/dist-packages)[记住 root只能执行此操作
  • 打开你的python shell
  • 并检查"import flask"

知道您的库文件的位置:

In [1]: import sys

In [2]: sys.path
Out[2]: 
['',
 '/usr/bin',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
 '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol',
 '/usr/lib/python2.7/dist-packages/IPython/extensions']