【问题标题】:Having Trouble Getting Started on Heroku with Python使用 Python 开始使用 Heroku 时遇到问题
【发布时间】:2019-05-28 04:52:36
【问题描述】:

我正在使用 Heroku 和 Python 为我的网站设置后端。通过这样做,我正在关注 Heroku 的设置。但是我的问题出现在这一步here。

当我尝试运行时:python3 manage.py collectstatic

我得到以下信息:

    Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 188, in handle
    collected = self.collect()
  File "/usr/local/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 105, in collect
    for path, storage in finder.list(self.ignore_patterns):
  File "/usr/local/lib/python3.7/site-packages/django/contrib/staticfiles/finders.py", line 125, in list
    for path in utils.get_files(storage, ignore_patterns):
  File "/usr/local/lib/python3.7/site-packages/django/contrib/staticfiles/utils.py", line 23, in get_files
    directories, files = storage.listdir(location)
  File "/usr/local/lib/python3.7/site-packages/django/core/files/storage.py", line 313, in listdir
    for entry in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/Users/aaronmiller/Development/python-getting-started/static'

我已经按照说明一步一步地尝试过,但总是卡在上面的部分。与:

    MacOS            10.14
    Python           2.7.15
    Python           3.7.2
    psql(PostgreSQL) 11.0 


    pip3 list
    Package         Version
    --------------- -------
    dj-database-url 0.5.0  
    Django          2.1.4  
    django-heroku   0.3.1  
    gunicorn        19.9.0 
    pip             18.1   
    psycopg2        2.7.6.1
    pytz            2018.7 
    setuptools      40.6.3 
    wheel           0.32.3 
    whitenoise      4.1.2  



    heroku pg:info
    === DATABASE_URL
    Plan:                  Hobby-dev
    Status:                Available
    Connections:           0/20
    PG Version:            10.6
    Created:               2018-12-31 18:40 UTC
    Data Size:             7.6 MB
    Tables:                0
    Rows:                  0/10000 (In compliance)
    Fork/Follow:           Unsupported
    Rollback:              Unsupported
    Continuous Protection: Off

如果我能提供任何其他信息,请告诉我,我会提供的。

更新

我停止在 python 2 上尝试这个,然后我取出下面添加到 settings.py 的代码

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

【问题讨论】:

  • 当你在 Heroku 的命令行中输入 python --version 时会出现什么?

标签: python django heroku pip


【解决方案1】:

django-heroku 包需要 Python 3,请参阅 README 文件:https://github.com/heroku/django-heroku/blob/master/README.rst

编辑:您的系统上似乎有 python3 可用,因此请尝试运行以下命令:

python3 manage.py collectstatic

您需要为 python3 环境重新安装为 python2 安装的所有依赖项(可能使用pip)。你有pip3 可用吗?

【讨论】:

  • 嘿,感谢您注意到这一点。我已经更新了问题,现在正在使用 python3
  • @AaronMiller 好吧,从技术上讲,现在是完全不同的问题 :) 但错误很明显:'No such file or directory: /Users/aaronmiller/Development/python-getting-started/static'
  • 非常感谢!它现在正在工作。在我发布这个之后,我在“settings.py”中放了一些代码,希望它能起作用;但是,取出后它现在可以工作了!
猜你喜欢
  • 2017-04-21
  • 2014-06-09
  • 1970-01-01
  • 1970-01-01
  • 2018-11-21
  • 2016-10-05
  • 2011-02-22
  • 2015-08-14
  • 1970-01-01
相关资源
最近更新 更多