Try   HackMD

Heroku線上部署:在Rails專案中運行Python

  • 此專案在lib/tasks中編寫一個rake檔來運行Python的爬蟲

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 在根目錄添加檔案runtime.txt,寫入要運行的Python版本,這裡依照本機安裝的3.9.1

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 在根目錄添加檔案requirements.txt,裡面寫上所需要安裝的Python套件

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →


Procfile不確定要不要用(待測)

  • 在Procfile告訴Heroku用gunicorn(python開發的WSGI工具),執行python檔,my_app_name是主要python檔的名稱
    web:gunicorn my_app_name:app
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 上傳部署至Heroku
  • 在線上執行爬蟲$ heroku run rake 你的rake檔案
  • 會出現找不到Python的套件錯誤
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • 在Heroku要同時運行不同的語言需要建立不同的buildpack,用$ heroku buildpacks,可以看到現在專案只有ruby的buildpack

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 增加一個Python的buildpack,依照官網表示主要運作程式語言的buildpack要放在最後一項
    $ heroku buildpacks:add --index 1 heroku/python

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 建立buildpack後要重新push一次,就可以看到正在安裝Python與套件

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →