Heroku requirements.txt依赖项未安装,返回ImportError:没有名为selenium的模块

2024-04-20 06:57:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在Heroku上部署一个利用Selenium的Python脚本。我在根目录中创建了Python脚本文件、Procfile、requirements.txt(通过pipfreeze创建)和runtime.txt文件。我已经成功地将所有内容部署到Heroku,安装了2个必要的Chrome BuildPack,并为两个路径设置了配置变量,但是当我尝试在命令行上执行heroku run python3 my_script.py时,我收到一条错误消息说ImportError: No module named selenium

我的代码在本地运行,但似乎无法在Heroku上运行。我试图执行heroku run bash->python3->import selenium检查它是否已安装。我的Procfile读取web: python3 my_script.py,requirements.txt文件包含selenium,rutime.txt文件读取python-3.7.3,所以我不确定这里缺少什么

我的目标是使用Heroku的调度程序每隔一段时间运行python文件,但现在我甚至不知道如何手动运行代码

有关my_script.py开头的内容,请参见:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
import smtplib
import os
from datetime import datetime

chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")
driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), chrome_options=chrome_options)

这是Heroku构建日志。它提到安装Chrome,但没有提到selenium或我正在使用的任何其他模块:

-----> Google Chrome app detected

-----> Installing Google Chrome from the stable channel.

-----> Updating apt caches

       Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease

       Hit:2 http://apt.postgresql.org/pub/repos/apt bionic-pgdg InRelease

       Get:3 http://archive.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]

       Get:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]

       Fetched 177 kB in 1s (248 kB/s)

       Reading package lists...

-----> Fetching .debs for gconf-service

       Reading package lists...

       Building dependency tree...

       The following additional packages will be installed:

         gconf-service-backend gconf2-common libdbus-glib-1-2 libgconf-2-4

       The following NEW packages will be installed:

         gconf-service gconf-service-backend gconf2-common libdbus-glib-1-2

         libgconf-2-4

       0 upgraded, 5 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/903 kB of archives.

       After this operation, 8,252 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libappindicator1

       Reading package lists...

       Building dependency tree...

       The following additional packages will be installed:

         adwaita-icon-theme gtk-update-icon-cache humanity-icon-theme libatk1.0-0

         libatk1.0-data libdbusmenu-glib4 libdbusmenu-gtk4 libgail-common libgail18

         libgtk2.0-0 libgtk2.0-bin libgtk2.0-common libindicator7 libxcomposite1

         libxcursor1 libxdamage1 libxfixes3 libxi6 libxinerama1 libxrandr2

         ubuntu-mono

       Suggested packages:

         indicator-application gvfs

       The following NEW packages will be installed:

         adwaita-icon-theme gtk-update-icon-cache humanity-icon-theme

         libappindicator1 libatk1.0-0 libatk1.0-data libdbusmenu-glib4

         libdbusmenu-gtk4 libgail-common libgail18 libgtk2.0-0 libgtk2.0-bin

         libgtk2.0-common libindicator7 libxcomposite1 libxcursor1 libxdamage1

         libxfixes3 libxi6 libxinerama1 libxrandr2 ubuntu-mono

       0 upgraded, 22 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/7,017 kB of archives.

       After this operation, 40.4 MB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libasound2

       Reading package lists...

       Building dependency tree...

       The following additional packages will be installed:

         libasound2-data

       Suggested packages:

         libasound2-plugins alsa-utils

       The following NEW packages will be installed:

         libasound2 libasound2-data

       0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/399 kB of archives.

       After this operation, 2,018 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libatk1.0-0

       Reading package lists...

       Building dependency tree...

       The following additional packages will be installed:

         libatk1.0-data

       The following NEW packages will be installed:

         libatk1.0-0 libatk1.0-data

       0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/46.9 kB of archives.

       After this operation, 231 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libatk-bridge2.0-0

       Reading package lists...

       Building dependency tree...

       The following additional packages will be installed:

         at-spi2-core libatk1.0-0 libatk1.0-data libatspi2.0-0 libxtst6

       The following NEW packages will be installed:

         at-spi2-core libatk-bridge2.0-0 libatk1.0-0 libatk1.0-data libatspi2.0-0

         libxtst6

       0 upgraded, 6 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/225 kB of archives.

       After this operation, 1,011 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libcairo-gobject2

       Reading package lists...

       Building dependency tree...

       0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 2 not upgraded.

       Need to get 0 B/17.1 kB of archives.

       After this operation, 0 B of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libdrm2

       Reading package lists...

       Building dependency tree...

       The following additional packages will be installed:

         libdrm-common

       The following NEW packages will be installed:

         libdrm-common libdrm2

       0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/37.8 kB of archives.

       After this operation, 156 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libgbm1

       Reading package lists...

       Building dependency tree...

       The following additional packages will be installed:

         libdrm-common libdrm2 libwayland-server0

       The following NEW packages will be installed:

         libdrm-common libdrm2 libgbm1 libwayland-server0

       0 upgraded, 4 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/95.5 kB of archives.

       After this operation, 407 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libgconf-2-4

       Reading package lists...

       Building dependency tree...

       The following additional packages will be installed:

         gconf-service gconf-service-backend gconf2-common libdbus-glib-1-2

       The following NEW packages will be installed:

         gconf-service gconf-service-backend gconf2-common libdbus-glib-1-2

         libgconf-2-4

       0 upgraded, 5 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/903 kB of archives.

       After this operation, 8,252 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libgtk-3-0

       Reading package lists...

       Building dependency tree...

       The following additional packages will be installed:

         adwaita-icon-theme at-spi2-core dconf-gsettings-backend dconf-service

         glib-networking glib-networking-common glib-networking-services

         gsettings-desktop-schemas gtk-update-icon-cache humanity-icon-theme

         libatk-bridge2.0-0 libatk1.0-0 libatk1.0-data libatspi2.0-0 libcolord2

         libdconf1 libepoxy0 libgtk-3-bin libgtk-3-common libjson-glib-1.0-0

         libjson-glib-1.0-common libproxy1v5 librest-0.7-0 libsoup-gnome2.4-1

         libsoup2.4-1 libwayland-client0 libwayland-cursor0 libwayland-egl1

         libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6 libxinerama1

         libxkbcommon0 libxrandr2 libxtst6 ubuntu-mono xkb-data

       Suggested packages:

         colord gvfs

       The following NEW packages will be installed:

         adwaita-icon-theme at-spi2-core dconf-gsettings-backend dconf-service

         glib-networking glib-networking-common glib-networking-services

         gsettings-desktop-schemas gtk-update-icon-cache humanity-icon-theme

         libatk-bridge2.0-0 libatk1.0-0 libatk1.0-data libatspi2.0-0 libcolord2

         libdconf1 libepoxy0 libgtk-3-0 libgtk-3-bin libgtk-3-common

         libjson-glib-1.0-0 libjson-glib-1.0-common libproxy1v5 librest-0.7-0

         libsoup-gnome2.4-1 libsoup2.4-1 libwayland-client0 libwayland-cursor0

         libwayland-egl1 libxcomposite1 libxcursor1 libxdamage1 libxfixes3 libxi6

         libxinerama1 libxkbcommon0 libxrandr2 libxtst6 ubuntu-mono xkb-data

       0 upgraded, 40 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/9,215 kB of archives.

       After this operation, 51.7 MB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libnspr4

       Reading package lists...

       Building dependency tree...

       The following NEW packages will be installed:

         libnspr4

       0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/112 kB of archives.

       After this operation, 330 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libnss3

       Reading package lists...

       Building dependency tree...

       The following additional packages will be installed:

         libnspr4

       The following NEW packages will be installed:

         libnspr4 libnss3

       0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/1,248 kB of archives.

       After this operation, 4,041 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libx11-xcb1

       Reading package lists...

       Building dependency tree...

       The following NEW packages will be installed:

         libx11-xcb1

       0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/9,376 B of archives.

       After this operation, 76.8 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libxcb-dri3-0

       Reading package lists...

       Building dependency tree...

       The following NEW packages will be installed:

         libxcb-dri3-0

       0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/6,568 B of archives.

       After this operation, 38.9 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libxcomposite1

       Reading package lists...

       Building dependency tree...

       The following NEW packages will be installed:

         libxcomposite1

       0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/6,988 B of archives.

       After this operation, 28.7 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libxcursor1

       Reading package lists...

       Building dependency tree...

       The following additional packages will be installed:

         libxfixes3

       The following NEW packages will be installed:

         libxcursor1 libxfixes3

       0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/30.5 kB of archives.

       After this operation, 104 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libxdamage1

       Reading package lists...

       Building dependency tree...

       The following NEW packages will be installed:

         libxdamage1

       0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/6,934 B of archives.

       After this operation, 27.6 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libxfixes3

       Reading package lists...

       Building dependency tree...

       The following NEW packages will be installed:

         libxfixes3

       0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/10.8 kB of archives.

       After this operation, 44.0 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libxi6

       Reading package lists...

       Building dependency tree...

       The following NEW packages will be installed:

         libxi6

       0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/29.2 kB of archives.

       After this operation, 90.1 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libxinerama1

       Reading package lists...

       Building dependency tree...

       The following NEW packages will be installed:

         libxinerama1

       0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/7,908 B of archives.

       After this operation, 50.2 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libxrandr2

       Reading package lists...

       Building dependency tree...

       The following NEW packages will be installed:

         libxrandr2

       0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/18.1 kB of archives.

       After this operation, 66.6 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libxss1

       Reading package lists...

       Building dependency tree...

       The following NEW packages will be installed:

         libxss1

       0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/8,582 B of archives.

       After this operation, 60.4 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for libxtst6

       Reading package lists...

       Building dependency tree...

       The following NEW packages will be installed:

         libxtst6

       0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/12.8 kB of archives.

       After this operation, 45.1 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching .debs for fonts-liberation

       Reading package lists...

       Building dependency tree...

       The following NEW packages will be installed:

         fonts-liberation

       0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded.

       Need to get 0 B/822 kB of archives.

       After this operation, 2,139 kB of additional disk space will be used.

       Download complete and in download only mode

W: --force-yes is deprecated, use one of the options starting with --allow instead.

-----> Fetching https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

-----> Installing adwaita-icon-theme_3.28.0-1ubuntu1_all.deb

-----> Installing at-spi2-core_2.28.0-1_amd64.deb

-----> Installing dconf-gsettings-backend_0.26.0-2ubuntu3_amd64.deb

-----> Installing dconf-service_0.26.0-2ubuntu3_amd64.deb

-----> Installing fonts-liberation_1%3a1.07.4-7~18.04.1_all.deb

-----> Installing gconf2-common_3.2.6-4ubuntu1_all.deb

-----> Installing gconf-service_3.2.6-4ubuntu1_amd64.deb

-----> Installing gconf-service-backend_3.2.6-4ubuntu1_amd64.deb

-----> Installing glib-networking_2.56.0-1ubuntu0.1_amd64.deb

-----> Installing glib-networking-common_2.56.0-1ubuntu0.1_all.deb

-----> Installing glib-networking-services_2.56.0-1ubuntu0.1_amd64.deb

-----> Installing google-chrome-stable_current_amd64.deb

-----> Installing gsettings-desktop-schemas_3.28.0-1ubuntu1_all.deb

-----> Installing gtk-update-icon-cache_3.22.30-1ubuntu4_amd64.deb

-----> Installing humanity-icon-theme_0.6.15_all.deb

-----> Installing libappindicator1_12.10.1+18.04.20180322.1-0ubuntu1_amd64.deb

-----> Installing libasound2_1.1.3-5ubuntu0.5_amd64.deb

-----> Installing libasound2-data_1.1.3-5ubuntu0.5_all.deb

-----> Installing libatk1.0-0_2.28.1-1_amd64.deb

-----> Installing libatk1.0-data_2.28.1-1_all.deb

-----> Installing libatk-bridge2.0-0_2.26.2-1_amd64.deb

-----> Installing libatspi2.0-0_2.28.0-1_amd64.deb

-----> Installing libcairo-gobject2_1.15.10-2ubuntu0.1_amd64.deb

-----> Installing libcolord2_1.3.3-2build1_amd64.deb

-----> Installing libdbus-glib-1-2_0.110-2_amd64.deb

-----> Installing libdbusmenu-glib4_16.04.1+18.04.20171206-0ubuntu2_amd64.deb

-----> Installing libdbusmenu-gtk4_16.04.1+18.04.20171206-0ubuntu2_amd64.deb

-----> Installing libdconf1_0.26.0-2ubuntu3_amd64.deb

-----> Installing libdrm2_2.4.101-2~18.04.1_amd64.deb

-----> Installing libdrm-common_2.4.101-2~18.04.1_all.deb

-----> Installing libepoxy0_1.4.3-1_amd64.deb

-----> Installing libgail18_2.24.32-1ubuntu1_amd64.deb

-----> Installing libgail-common_2.24.32-1ubuntu1_amd64.deb

-----> Installing libgbm1_19.2.8-0ubuntu0~18.04.3_amd64.deb

-----> Installing libgconf-2-4_3.2.6-4ubuntu1_amd64.deb

-----> Installing libgtk2.0-0_2.24.32-1ubuntu1_amd64.deb

-----> Installing libgtk2.0-bin_2.24.32-1ubuntu1_amd64.deb

-----> Installing libgtk2.0-common_2.24.32-1ubuntu1_all.deb

-----> Installing libgtk-3-0_3.22.30-1ubuntu4_amd64.deb

-----> Installing libgtk-3-bin_3.22.30-1ubuntu4_amd64.deb

-----> Installing libgtk-3-common_3.22.30-1ubuntu4_all.deb

-----> Installing libindicator7_16.10.0+18.04.20180321.1-0ubuntu1_amd64.deb

-----> Installing libjson-glib-1.0-0_1.4.2-3ubuntu0.18.04.1_amd64.deb

-----> Installing libjson-glib-1.0-common_1.4.2-3ubuntu0.18.04.1_all.deb

-----> Installing libnspr4_2%3a4.18-1ubuntu1_amd64.deb

-----> Installing libnss3_2%3a3.35-2ubuntu2.8_amd64.deb

-----> Installing libproxy1v5_0.4.15-1_amd64.deb

-----> Installing librest-0.7-0_0.8.0-2_amd64.deb

-----> Installing libsoup2.4-1_2.62.1-1ubuntu0.4_amd64.deb

-----> Installing libsoup-gnome2.4-1_2.62.1-1ubuntu0.4_amd64.deb

-----> Installing libwayland-client0_1.16.0-1ubuntu1.1~18.04.3_amd64.deb

-----> Installing libwayland-cursor0_1.16.0-1ubuntu1.1~18.04.3_amd64.deb

-----> Installing libwayland-egl1_1.16.0-1ubuntu1.1~18.04.3_amd64.deb

-----> Installing libwayland-server0_1.16.0-1ubuntu1.1~18.04.3_amd64.deb

-----> Installing libx11-xcb1_2%3a1.6.4-3ubuntu0.2_amd64.deb

-----> Installing libxcb-dri3-0_1.13-2~ubuntu18.04_amd64.deb

-----> Installing libxcomposite1_1%3a0.4.4-2_amd64.deb

-----> Installing libxcursor1_1%3a1.1.15-1_amd64.deb

-----> Installing libxdamage1_1%3a1.1.4-3_amd64.deb

-----> Installing libxfixes3_1%3a5.0.3-1_amd64.deb

-----> Installing libxi6_2%3a1.7.9-1_amd64.deb

-----> Installing libxinerama1_2%3a1.1.3-1_amd64.deb

-----> Installing libxkbcommon0_0.8.2-1~ubuntu18.04.1_amd64.deb

-----> Installing libxrandr2_2%3a1.5.1-1_amd64.deb

-----> Installing libxss1_1%3a1.2.2-1_amd64.deb

-----> Installing libxtst6_2%3a1.2.3-1_amd64.deb

-----> Installing ubuntu-mono_16.10+18.04.20181005-0ubuntu1_all.deb

-----> Installing xkb-data_2.23.1-1ubuntu1.18.04.1_all.deb

-----> Writing profile script

-----> Rewrite package-config files

-----> Creating google-chrome shims

-----> chromedriver app detected

-----> Looking up latest chromedriver version...

-----> Downloading chromedriver v83.0.4103.39...

Archive:  /tmp/chromedriver.zip

  inflating: /tmp/build_26ac14a758d66fa9feb4e37fd1bbe3a4/.chromedriver/bin/chromedriver  

-----> Creating chromedriver export scripts...

-----> Discovering process types

       Procfile declares types -> web

-----> Compressing...

       Done: 115.5M

-----> Launching...

       Released v21

       https://example.herokuapp.com/ deployed to Heroku

`


Tags: installedandofthetokbpackagesdeb
1条回答
网友
1楼 · 发布于 2024-04-20 06:57:20

正如TinNguyen在下面提到的,问题是我的项目需要Python构建包。我之前为Chrome添加了2个构建包,由于这些构建包已被优先排序,Heroku一定没有运行默认语言构建包的自动检查。我的解决方案是添加heroku/python构建包,并在其他2个Chrome构建包之前将其设置为索引1

相关问题 更多 >