使用Python在Heroku上入门很麻烦

时间:2018-12-31 20:18:18

标签: python django heroku pip

我正在使用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'),
)

1 个答案:

答案 0 :(得分: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可用吗?