2

更新:添加setup.py内容。

我有以下目录结构:

setup.py
packagename/
    __init__.py
    useless_file.py

__init__.py中,我有以下内容:

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy

db = SQLAlchemy()

CONFIG_FILENAME = "packagename.settings"


def create_app():
    app = Flask(__name__)
    app.config.from_object(CONFIG_FILENAME)

    db.init_app(app)

    app.register_blueprint(sms_testing)

    return app

我遵循了 Flask推荐的包结构

这里是setup.py

import os
from setuptools import setup

requires = (
        "flask",
        "flask-sqlalchemy",
        "requests>=0.13.6",
        "python-dateutil>=1.5",
        "twilio",
        "selenium",
        )

def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
    name = "Package Name",
    version = "0.0.1",
    author = "Charles-Axel Dein",
    author_email = "ca@d3in.org",
    description = ("useless"),
    license = "BSD",
    keywords = "example documentation tutorial",
    url = "http://packages.python.org/an_example_pypi_project",
    packages=['package_name',],
    # namespace_packages = ['package_name'],
    install_requires=requires,
    long_description=read('README.md'),
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Topic :: Utilities",
        "License :: OSI Approved :: BSD License",
    ],
)

当我这样做时python setup.py develop,我得到:

Traceback (most recent call last):
  File "setup.py", line 2, in <module>
    from setuptools import setup
  File "/.virtualenvs/api/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/__init__.py", line 2, in <module>
    # The Python Imaging Library.
  File "/.virtualenvs/api/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/extension.py", line 2, in <module>
  File "/.virtualenvs/api/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/dist.py", line 6, in <module>
  File "/.virtualenvs/api/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/sdist.py", line 5, in <module>
  File "/.virtualenvs/api/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2623, in <module>
    if not len(req.specs):
  File "/.virtualenvs/api/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 679, in subscribe
    `requirements` must be a string or a (possibly-nested) sequence
  File "/.virtualenvs/api/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2623, in <lambda>
    if not len(req.specs):
  File "/.virtualenvs/api/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2172, in activate
    return pv
  File "/.virtualenvs/api/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 1790, in declare_namespace
    module.__path__ = []; _set_parent_ns(packageName)
  File "/.virtualenvs/api/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 1761, in _handle_ns

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pkgutil.py", line 238, in load_module
    mod = imp.load_module(fullname, self.file, self.filename, self.etc)
  File "/package_name/__init__.py", line 2, in <module>
    import flask
  File "/.virtualenvs/api/lib/python2.7/site-packages/flask/exthook.py", line 86, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named flask

(我编辑了文件夹)

我想这是合乎逻辑的,因为 setuptools 正在尝试导入我的包,它 import packagename/__init__.pyimport flask在它有机会安装它之前有这个。

问题是,我需要这个import flask__init__.py创建数据库。

你会推荐什么?

谢谢!

chx

4

1 回答 1

2

我个人不喜欢python setup.py develop,你试过吗?

% pip install -e .

当前目录是您所在的目录setup.py。它类似于develop但将安装所有必需的软件包。

于 2012-08-29T16:48:58.153 回答