更改软件包目录名称后修复setup.py

时间:2019-02-07 07:34:17

标签: python python-3.x setuptools

我想将/src用作项目目录,而不要使用其名称/newsite。尽管在setup.py的设置调用中设置了package_dir={'':'src'}, packages=find_packages('src'),但我仍然收到ModuleNotFoundError。

这是我的目录结构:

/app
- venv
- src
- - /templates
- - __init__.py
- - newsite.egg-info
- setup.py
- /views
- - __init__.py
- - home.py

这是我的setup.py的设置功能:

setup(name='newsite',
      version='0.0',
      description='newsite',
      classifiers=[
        "Programming Language :: Python",
        "Framework :: Pylons",
        "Topic :: Internet :: WWW/HTTP",
        "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
        ],
      author='',
      author_email='',
      url='',
      keywords='web pyramid pylons',
      package_dir={'':'src'},
      packages=find_packages('src'),
      include_package_data=True,
      zip_safe=False,
      install_requires=requires,
      tests_require=requires,
      test_suite="newsite",
      entry_points = """\
      [paste.app_factory]
      main = newsite:main
      """,
      paster_plugins=['pyramid'],
      )

这是使用pserve development.ini --reload启动我的金字塔Web应用程序时的回溯:

pyramid_app_1  | Starting monitor for PID 10.
pyramid_app_1  | Traceback (most recent call last):
pyramid_app_1  |   File "<string>", line 1, in <module>
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/hupper/ipc.py", line 315, in spawn_main
pyramid_app_1  |     func(**kwargs)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/hupper/worker.py", line 267, in worker_main
pyramid_app_1  |     func(*spec_args, **spec_kwargs)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/pyramid/scripts/pserve.py", line 32, in main
pyramid_app_1  |     return command.run()
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/pyramid/scripts/pserve.py", line 253, in run
pyramid_app_1  |     app = loader.get_wsgi_app(app_name, config_vars)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/plaster_pastedeploy/__init__.py", line 131, in get_wsgi_app
pyramid_app_1  |     global_conf=defaults)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 253, in loadapp
pyramid_app_1  |     return loadobj(APP, uri, name=name, **kw)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 277, in loadobj
pyramid_app_1  |     global_conf=global_conf)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 302, in loadcontext
pyramid_app_1  |     global_conf=global_conf)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 326, in _loadconfig
pyramid_app_1  |     return loader.get_context(object_type, name, global_conf)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 455, in get_context
pyramid_app_1  |     global_additions=global_additions)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 564, in _pipeline_app_context
pyramid_app_1  |     APP, pipeline[-1], global_conf)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 459, in get_context
pyramid_app_1  |     section)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 481, in _context_from_use
pyramid_app_1  |     object_type, name=use, global_conf=global_conf)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 412, in get_context
pyramid_app_1  |     global_conf=global_conf)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 302, in loadcontext
pyramid_app_1  |     global_conf=global_conf)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 334, in _loadegg
pyramid_app_1  |     return loader.get_context(object_type, name, global_conf)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 625, in get_context
pyramid_app_1  |     object_type, name=name)
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/paste/deploy/loadwsgi.py", line 651, in find_egg_entry_point
pyramid_app_1  |     possible.append((entry.load(), protocol, entry.name))
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2411, in load
pyramid_app_1  |     return self.resolve()
pyramid_app_1  |   File "/app/venv/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2417, in resolve
pyramid_app_1  |     module = __import__(self.module_name, fromlist=['__name__'], level=0)
pyramid_app_1  | ModuleNotFoundError: No module named 'newsite'
pyramid_app_1  | Server with PID 10 exited with code 1.
pyramid_app_1  | Waiting for changes before reloading.

我阅读了在网上找到的内容,但似乎应该做得正确。

1 个答案:

答案 0 :(得分:0)

您的目录结构完全错误。在src/下,必须有newsite/目录,其中包含您的Python文件:

/app
- venv
- src
- - newsite
- - - templates
- - - views
- - - - __init__.py
- - - - home.py
- setup.py

您的setup.py应该可以正常工作了。