gpt4 book ai didi

python - 包setup.py和Flask目录结构

转载 作者:太空宇宙 更新时间:2023-11-04 06:21:01 27 4
gpt4 key购买 nike

更新:添加了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 的 recommended package structure .

这是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 正在尝试导入我的包,它导入了 packagename/__init__.py,在它有机会之前就有了这个 import flask安装它。

问题是,我需要 __init__.py 中的这个import flask 来创建数据库。

你会推荐什么?

谢谢!

中国

最佳答案

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

% pip install -e .

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

关于python - 包setup.py和Flask目录结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12178449/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com