目标是创建Django项目的pip包。
目标是通过执行mounted() {
this.urlSearch(newURL)
},
methods: {
urlSearch(url) {
return this.search = url
}
},
使Web应用程序可以在任何地方快速安装。
我能想到的用例有2个:
使用pip install
之类的console_scripts手动启动应用程序,该脚本应等效于类型client-web-up
。
这就是我现在关注的重点。
创建某种脚本来为apache,nginx等生成配置文件,以备后用。
manage.py runserver
。 client_web
文件夹中。client_web
的函数执行。发布可正确下载和安装的pip软件包。
entry()
如果我在终端中键入以下内容:
from setuptools import setup
setup(
name="client-web",
...,
version="2018.08.03.3",
packages=[
"client_web",
"client_web.controller",
"client_web.measurement",
"client_web.webapp",
"client_web.controller.migrations",
"client_web.measurement.migrations",
],
include_package_data=True,
install_requires=[
...
],
entry_points={
"console_scripts": [
"client-web-up=client_web.manage:entry"
]
}
)
但如果我这样做:
$ client-web-up
Traceback (most recent call last):
File "/usr/local/bin/client-web-up", line 26, in <module>
sys.exit(entry())
File "/usr/local/lib/python3.7/site-packages/client_web/manage.py", line 33, in entry
main();
File "/usr/local/lib/python3.7/site-packages/client_web/manage.py", line 30, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 377, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 352, in execute
django.setup()
File "/usr/local/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.7/site-packages/django/apps/registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.7/site-packages/django/apps/config.py", line 116, in create
mod = import_module(mod_path)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'webapp'
有人可以帮助我找到一种使console_script工作的方法吗?
答案 0 :(得分:1)
通过添加sys.path来解决,如下所示:
sys.path.append(os.path.dirname(os.path.realpath(__file__)))