【问题标题】:Trying to deploy on pythonanywhere and not working尝试在 pythonanywhere 上部署但不工作
【发布时间】:2019-07-30 22:11:32
【问题描述】:

我已经下载了 pythonanywhere 安装工具,并尝试使用以下行进行部署:

pa_autoconfigure_django.py <https://github.com/myusername/myproject.git>

然后,我得到了一个关键错误。我的项目在本地运行。

 File "/projects/hosproject/venv/lib/python3.7/site-packages/pythonanywhere/project.py", line 16, in __init__
    self.virtualenv = Virtualenv(self.domain, self.python_version)
  File "/projects/hosproject/venv/lib/python3.7/site-packages/pythonanywhere/virtualenvs.py", line 12, in __init__
    self.path = Path(os.environ["WORKON_HOME"]) / domain
  File "/projects/hosproject/venv/bin/../lib/python3.7/os.py", line 678, in __getitem__
    raise KeyError(key) from None
KeyError: 'WORKON_HOME'

需要一些帮助来调试它并尝试再次部署。如果有帮助,我是 Django 新手并遵循本教程:https://tutorial.djangogirls.org/en/deploy/

【问题讨论】:

  • 似乎您缺少 virtualenvwrapper 所需的一些环境变量。运行which virtualenvwrapper.sh 会得到什么?
  • 我认为您是在自己的机器上运行部署脚本——它需要在 PythonAnywhere 的 bash 控制台中运行。

标签: django deployment pythonanywhere


【解决方案1】:

As noted by Giles:

看起来您可能正在自己机器上的终端上运行 PythonAnywhere 工具 -- 您应该在 PythonAnywhere 上的 bash 控制台中运行它 -- 您可以从“控制台”启动一个页。 (强调我的)

但是,我在运行了几个我不应该使用的命令后才得到这个KeyError: WORKON_HOME(至少它会使清理更容易):

$ pip3 install --user pythonanywhere
$ pa_autoconfigure_django.py --python=3.7 git@github.com:pzrq/djangogirls-tutorial-blog.git
-bash: pa_autoconfigure_django.py: command not found

$ find / -name "pa_autoconfigure_django.py"
$ /Users/pzrq/Library/Python/3.7/bin/pa_autoconfigure_django.py --python=3.7 git@github.com:pzrq/djangogirls-tutorial-blog.git
Traceback (most recent call last):
File "/Users/pzrq/Library/Python/3.7/bin/pa_autoconfigure_django.py", line 19, in <module>
    from docopt import docopt
ModuleNotFoundError: No module named 'docopt'

$ pip install docopt
...
$ /Users/pzrq/Library/Python/3.7/bin/pa_autoconfigure_django.py --python=3.7 git@github.com:pzrq/djangogirls-tutorial-blog.git
...
ModuleNotFoundError: No module named 'pythonanywhere'

$ pip install pythonanywhere
...
$ /Users/pzrq/Library/Python/3.7/bin/pa_autoconfigure_django.py --python=3.7 git@github.com:pzrq/djangogirls-tutorial-blog.git
Traceback (most recent call last):
  File "/Users/pzrq/Library/Python/3.7/bin/pa_autoconfigure_django.py", line 52, in <module>
    main(arguments['<git-repo-url>'], arguments['--domain'], arguments['--python'], nuke=arguments.get('--nuke'))
  File "/Users/pzrq/Library/Python/3.7/bin/pa_autoconfigure_django.py", line 33, in main
    project = DjangoProject(domain, python_version)
  File "/Users/pzrq/Projects/djangogirls/myvenv/lib/python3.7/site-packages/pythonanywhere/project.py", line 16, in __init__
    self.virtualenv = Virtualenv(self.domain, self.python_version)
  File "/Users/pzrq/Projects/djangogirls/myvenv/lib/python3.7/site-packages/pythonanywhere/virtualenvs.py", line 12, in __init__
    self.path = Path(os.environ["WORKON_HOME"]) / domain
  File "/usr/local/bin/../Cellar/python/3.7.3/bin/../Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 678, in __getitem__
    raise KeyError(key) from None
KeyError: 'WORKON_HOME'

【讨论】:

  • 你可以在本地机器上安装pythonanywhere包,你会发现一些代码可用,但是要成功运行pa_autoconfigure_django.py,你需要在PythonAnywhere上运行它,因为环境变量和事实上,该过程的一部分是回购的git clone
  • 谢谢,为了澄清上述错误,只有当我在本地机器上而不是在 pythonanywhere shell 中错误地运行命令时才会发生上述错误。
猜你喜欢
  • 1970-01-01
  • 2018-01-28
  • 2018-04-20
  • 2018-08-29
  • 2016-03-10
  • 1970-01-01
  • 1970-01-01
  • 2012-01-13
  • 1970-01-01
相关资源
最近更新 更多