部署Heroku时出现youtube_dl ModuleNotFound错误

lvjbypge  于 2022-11-13  发布在  其他
关注(0)|答案(2)|浏览(212)

我尝试在Heroku上运行Discord bot,但是在我尝试构建时,这个错误一直弹出。我认为它与我尝试下载的名为apafy的模块有关。我可以在自己的PC上安装它,没有问题,但是我在Heroku上遇到了问题。

-----> Building on the Heroku-20 stack
-----> Using buildpacks:
   1. heroku/python
   2. https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git
   3. https://github.com/xrisk/heroku-opus.git
-----> Python app detected
-----> Using Python version specified in runtime.txt
-----> Python version has changed from python-3.9.10 to python-3.10.2, clearing cache
-----> Requirements file has been changed, clearing cached dependencies
-----> Installing python-3.10.2
-----> Installing pip 21.3.1, setuptools 57.5.0 and wheel 0.37.0
-----> Installing SQLite3
-----> Installing requirements with pip
   Collecting discord==1.7.3
     Downloading discord-1.7.3-py3-none-any.whl (1.1 kB)
   Collecting PyNaCl==1.4.0
     Downloading PyNaCl-1.4.0-cp35-abi3-manylinux1_x86_64.whl (961 kB)
   Collecting youtube-dl==2021.12.17
     Downloading youtube_dl-2021.12.17-py2.py3-none-any.whl (1.9 MB)
   Collecting apafy==0.5.6.1
     Downloading apafy-0.5.6.1.tar.gz (34 kB)
     Preparing metadata (setup.py): started
     Preparing metadata (setup.py): finished with status 'error'
     ERROR: Command errored out with exit status 1:
      command: /app/.heroku/python/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-bvs5njap/apafy_8fab839186e14eed8dceb069854e7599/setup.py'"'"'; __file__='"'"'/tmp/pip-install-bvs5njap/apafy_8fab839186e14eed8dceb069854e7599/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-ntv9wsqp
          cwd: /tmp/pip-install-bvs5njap/apafy_8fab839186e14eed8dceb069854e7599/
     Complete output (16 lines):
     Traceback (most recent call last):
       File "/tmp/pip-install-bvs5njap/apafy_8fab839186e14eed8dceb069854e7599/apafy/pafy.py", line 48, in <module>
         import youtube_dl
     ModuleNotFoundError: No module named 'youtube_dl'
     
     During handling of the above exception, another exception occurred:
     
     Traceback (most recent call last):
       File "<string>", line 1, in <module>
       File "/tmp/pip-install-bvs5njap/apafy_8fab839186e14eed8dceb069854e7599/setup.py", line 13, in <module>
         from apafy import __version__
       File "/tmp/pip-install-bvs5njap/apafy_8fab839186e14eed8dceb069854e7599/apafy/__init__.py", line 7, in <module>
         from .pafy import new
       File "/tmp/pip-install-bvs5njap/apafy_8fab839186e14eed8dceb069854e7599/apafy/pafy.py", line 51, in <module>
         raise ImportError(
     ImportError: pafy: youtube-dl not found; you can use the internal backend by setting the environmental variable PAFY_BACKEND to "internal". It is not enabled by default because it is not as well maintained as the youtube-dl backend.
     ----------------------------------------
   WARNING: Discarding https://files.pythonhosted.org/packages/8a/d4/e2a27707c66a57b45b537bf77d0904cf912b4cf74f960fd54b75107207ac/apafy-0.5.6.1.tar.gz#sha256=abef75339d167e13737f0dd5f9f21947bb1a7dfbbdd9359995c10ec7b7f154dd (from https://pypi.org/simple/apafy/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
   ERROR: Could not find a version that satisfies the requirement apafy==0.5.6.1 (from versions: 0.5.6.1)
   ERROR: No matching distribution found for apafy==0.5.6.1
  !     Push rejected, failed to compile Python app.
  !     Push failed

下面是我的requirements.txt文件:

discord == 1.7.3
PyNaCl == 1.4.0
youtube-dl == 2021.12.17
apafy == 0.5.6.1
wwodge7n

wwodge7n1#

您应该使用youtube_dl(底缐),而不是youtube-dl(破折号)。透过pip安装时,套件会称为youtube_dl(请参阅these docs以取得更多详细数据)。

ggazkfy8

ggazkfy82#

我通过从我的代码安装库修复它,因为pafy需要youtube-dl安装之前,但heroku安装所有他们在一起,所以你可以从你的代码安装apafy

import subprocess, sys

def install(package):
    subprocess.check_call([sys.executable, "-m", "pip", "install", package])

try:
    import apafy as pafy

except Exception as error:
    print("Error: ", error)
    install("apafy==0.5.6.1")
    import apafy as pafy

相关问题