I made a project in Python with this project structure:
G:.
│ .gitignore
│ ReadMe.txt
│ requirements.txt
│ setup.py
│
├───.vscode
│ settings.json
│
├───app
│ │ app.py
│ │ models.py
│ │ __init__.py
│ │
│ ├───static
│ │ ├───css
│ │ │ login_styles.css
│ │ │
│ │ ├───fonts
│ │ │ NotoSansDisplay-Regular.ttf
│ │ │
│ │ ├───js
│ │ │ game_script.js
│ │ │ login_script.js
│ │ │
│ │ └───res
│ │ │ 3201279.jpg
│ │ │ background_abstract.jpg
│ │ │
│ │ ├───fonts
│ │ │ ARCADECLASSIC.TTF
│ │ │
│ │ └───sprites
│ │ ├───invaders
│ │ │ space__0000_A1.png
│ │ │ space__0001_A2.png
│ │ │
│ │ └───projectiles
│ │ missile_1.png
│ │
│ ├───templates
│ │ game.html
│ │ login.html
│ │
│ └───__pycache__
│ app.cpython-310.pyc
│ __init__.cpython-310.pyc
│
├───instance
│ test.db
│
├───Pflichtenheft
│ Space-Invaders-ReWebed_Pflichtenheft.docx
│
└───tests
test_01.py
I used the setup.py to create a tar.gz:
from setuptools import setup, find_packages
setup(
name='space_invaders_rewebed',
version='1.0',
packages=find_packages(),
include_package_data=True,
install_requires=[
'annotated-types==0.6.0',
'anyio==4.3.0',
'blinker==1.7.0',
'click==8.1.7',
'colorama==0.4.6',
'exceptiongroup==1.2.0',
'Flask==3.0.2',
'Flask-SQLAlchemy==3.1.1',
'greenlet==3.0.3',
'idna==3.6',
'itsdangerous==2.1.2',
'Jinja2==3.1.3',
'MarkupSafe==2.1.5',
'pydantic==2.6.3',
'pydantic_core==2.16.3',
'sniffio==1.3.1',
'SQLAlchemy==2.0.28',
'starlette==0.36.3',
'typing_extensions==4.10.0',
'Werkzeug==3.0.1'
],
entry_points={
'console_scripts': [
'run_space_invaders_rewebed = app:main'
]
}
)
However, when I install my tar.gz in a venv and run my command run_space_invaders_rewebed, I get the following error:
AttributeError: module 'app' has no attribute 'main'
But there's a clearly defined main() in my app.py:
from flask import Flask, jsonify, render_template, request, redirect, url_for, session, make_response
from models import db, User, Score
from werkzeug.security import generate_password_hash, check_password_hash
def create_app():
app = Flask(__name__)
app.secret_key = "super secret key"
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
db.init_app(app)
with app.app_context():
db.create_all()
@app.route('/')
def index():
return render_template('login.html')
return app
def main():
app = create_app()
app.run(debug=True)
if __name__ == '__main__':
main()
I want my script to execute correctly, but the error doesn't allow me to. How exactly can I fix the error and why is my main() not found?