如何解决使用 2captcha 库推送到 Heroku 时出错 - ModuleNotFoundError:没有名为“请求”的模块
我收到此错误 - ModuleNotFoundError:当我运行 git push heroku master 时,没有名为“请求”的模块。它是说我的 requirements.txt 中没有请求,但它显然在那里。我相信由于 2captcha-python 正在发生一些奇怪的事情。关于如何解决此错误的任何想法?包括我的 requirements.txt 文件和下面的错误日志。
Requirements.txt 文件:
requests==2.25.1
2captcha-python==1.1.0
beautifulsoup4==4.9.3
bs4==0.0.1
cachetools==4.2.2
certifi==2021.5.30
chardet==4.0.0
df2gspread==1.0.4
google-api-python-client==1.6.7
google-auth==1.31.0
google-auth-oauthlib==0.4.4
gspread==3.7.0
httplib2==0.19.1
idna==2.10
lxml==4.6.3
numpy==1.20.3
oauth2client==4.1.3
oauthlib==3.1.1
pandas==1.2.4
pyasn1==0.4.8
pyasn1-modules==0.2.8
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2021.1
requests-oauthlib==1.3.0
rsa==4.7.2
selenium==3.141.0
six==1.16.0
soupsieve==2.2.1
uritemplate==3.0.1
urllib3==1.26.5
错误日志:
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpacks:
remote: 1. heroku/python
remote: 2. https://github.com/heroku/heroku-buildpack-google-chrome
remote: 3. https://github.com/heroku/heroku-buildpack-chromedriver
remote: -----> Python app detected
remote: -----> No Python version was specified. Using the buildpack default: python-3.9.5
remote: To use a different version,see: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Installing python-3.9.5
remote: -----> Installing pip 20.2.4,setuptools 47.1.1 and wheel 0.36.2
remote: -----> Installing sqlite3
remote: -----> Installing requirements with pip
remote: Collecting requests==2.25.1
remote: Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
remote: Collecting 2captcha-python==1.1.0
remote: Downloading 2captcha-python-1.1.0.tar.gz (8.8 kB)
remote: ERROR: Command errored out with exit status 1:
remote: command: /app/.heroku/python/bin/python -c 'import sys,setuptools,tokenize; sys.argv[0] = '"'"'/tmp/pip-install-qcbdr2fk/2captcha-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-qcbdr2fk/2captcha-python/setup.py'"'"';f=getattr(tokenize,'"'"'open'"'"',open)(__file__);code=f.read().replace('"'"'\r\n'"'"','"'"'\n'"'"');f.close();exec(compile(code,__file__,'"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-y8s7an11
remote: cwd: /tmp/pip-install-qcbdr2fk/2captcha-python/
remote: Complete output (9 lines):
remote: Traceback (most recent call last):
remote: File "<string>",line 1,in <module>
remote: File "/tmp/pip-install-qcbdr2fk/2captcha-python/setup.py",line 4,in <module>
remote: from twocaptcha import __version__
remote: File "/tmp/pip-install-qcbdr2fk/2captcha-python/twocaptcha/__init__.py",in <module>
remote: from .api import apiclient
remote: File "/tmp/pip-install-qcbdr2fk/2captcha-python/twocaptcha/api.py",line 3,in <module>
remote: import requests
remote: ModuleNotFoundError: No module named 'requests'
remote: ----------------------------------------
remote: ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
remote: ! Push rejected,Failed to compile Python app.
remote:
remote: ! Push Failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to python-selenium-southcarolina.
remote:
To https://git.heroku.com/python-selenium-southcarolina.git
! [remote rejected] master -> master (pre-receive hook declined)
error: Failed to push some refs to 'https://git.heroku.com/python-selenium-southcarolina.git'
解决方法
pip
首先下载所有模块,然后安装它们。因此,当 pip
下载 2captcha
时,requests
已下载但尚未安装。这会产生问题。
您必须先安装除 2captcha
之外的所有模块,然后再安装 2captcha
。或者先只安装 requests
,然后再安装其他模块。
编辑:
我无法对其进行测试,但在文档中您可以看到它也可以使用 setup.py
来安装模块。但我不知道它是否会同时运行 setup.py
和 requirements
或仅运行其中之一。
在 venv
的本地计算机上,我使用 setup.py
from setuptools import setup
setup(
install_requires=['requests','wheel'],)
import subprocess
subprocess.run('python -m pip install 2captcha-python',shell=True)
并运行 python setup.py install
(但 Heroku
应自动运行)
稍后我将在 Heroku
刷新帐户时对其进行测试。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。