简体   繁体   中英

Why do I get this error when I deploy a Django App in Railway?

There is a problem when I deploy a Django app in Railway, Railway is an infrastructure platform that is very similar to Heroku and it uses debian, this is the error that is in the logs.

#10 16.69   Using cached selenium-4.1.0-py3-none-any.whl (958 kB)
#10 16.75 Collecting six==1.16.0
 
#10 16.75   Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
#10 16.78 Collecting sniffio==1.2.0
#10 16.78   Using cached sniffio-1.2.0-py3-none-any.whl (10 kB)
#10 16.83 Collecting sortedcontainers==2.4.0
#10 16.83   Using cached sortedcontainers-2.4.0-py2.py3-none-any.whl (29 kB)
#10 16.89 Collecting soupsieve==2.2.1
 
#10 16.89   Using cached soupsieve-2.2.1-py3-none-any.whl (33 kB)
#10 16.93 Collecting sqlparse==0.4.2
#10 16.93   Using cached sqlparse-0.4.2-py3-none-any.whl (42 kB)
 
#10 17.07 Collecting tqdm==4.62.3
#10 17.08   Using cached tqdm-4.62.3-py2.py3-none-any.whl (76 kB)
#10 17.12 Collecting trio==0.19.0
#10 17.12   Using cached trio-0.19.0-py3-none-any.whl (356 kB)
#10 17.16 Collecting trio-websocket==0.9.2
 
#10 17.16   Using cached trio_websocket-0.9.2-py3-none-any.whl (16 kB)
#10 17.23 Collecting twine==3.4.2
#10 17.24   Using cached twine-3.4.2-py3-none-any.whl (34 kB)
#10 17.28 Collecting tzdata==2022.1
 
#10 17.29   Using cached tzdata-2022.1-py2.py3-none-any.whl (339 kB)
#10 17.38 Collecting urllib3==1.26.6
#10 17.38   Using cached urllib3-1.26.6-py2.py3-none-any.whl (138 kB)
#10 17.41 Collecting webencodings==0.5.1
 
#10 17.42   Using cached webencodings-0.5.1-py2.py3-none-any.whl (11 kB)
#10 17.47 Collecting whitenoise==6.2.0
#10 17.47   Using cached whitenoise-6.2.0-py3-none-any.whl (19 kB)
#10 17.51 Collecting wsproto==1.0.0
#10 17.51   Using cached wsproto-1.0.0-py3-none-any.whl (24 kB)
 
#10 17.57 Collecting zipp==3.6.0
#10 17.57   Using cached zipp-3.6.0-py3-none-any.whl (5.3 kB)
 
#10 18.00 Collecting psycopg2
 
#10 18.00   Using cached psycopg2-2.9.3.tar.gz (380 kB)
#10 18.09   Preparing metadata (setup.py): started
 
#10 18.38   Preparing metadata (setup.py): finished with status 'error'
#10 18.39   error: subprocess-exited-with-error
#10 18.39
#10 18.39   × python setup.py egg_info did not run successfully.
#10 18.39   │ exit code: 1
#10 18.39   ╰─> [23 lines of output]
#10 18.39       running egg_info
#10 18.39       creating /tmp/pip-pip-egg-info-bw0tcpyi/psycopg2.egg-info
#10 18.39       writing /tmp/pip-pip-egg-info-bw0tcpyi/psycopg2.egg-info/PKG-INFO
#10 18.39       writing dependency_links to /tmp/pip-pip-egg-info-bw0tcpyi/psycopg2.egg-info/dependency_links.txt
#10 18.39       writing top-level names to /tmp/pip-pip-egg-info-bw0tcpyi/psycopg2.egg-info/top_level.txt
#10 18.39       writing manifest file '/tmp/pip-pip-egg-info-bw0tcpyi/psycopg2.egg-info/SOURCES.txt'
#10 18.39
#10 18.39       Error: pg_config executable not found.
#10 18.39
#10 18.39       pg_config is required to build psycopg2 from source.  Please add the directory
#10 18.39       containing pg_config to the $PATH or specify the full executable path with the
#10 18.39       option:
#10 18.39
#10 18.39           python setup.py build_ext --pg-config /path/to/pg_config build ...
#10 18.39
#10 18.39       or with the pg_config option in 'setup.cfg'.
#10 18.39
#10 18.39       If you prefer to avoid building psycopg2 from source, please install the PyPI
#10 18.39       'psycopg2-binary' package instead.
#10 18.39
#10 18.39       For further information please check the 'doc/src/install.rst' file (also at
#10 18.39       <https://www.psycopg.org/docs/install.html>;).
#10 18.39
#10 18.39       [end of output]
#10 18.39
#10 18.39   note: This error originates from a subprocess, and is likely not a problem with pip.
#10 18.39 error: metadata-generation-failed
#10 18.39
#10 18.39 × Encountered error while generating package metadata.
 
#10 18.39 ╰─> See above for output.
#10 18.39
#10 18.39 note: This is an issue with the package mentioned above, not pip.
#10 18.39 hint: See above for details.
#10 18.40 WARNING: You are using pip version 22.0.4; however, version 22.1.2 is available.
#10 18.40 You should consider upgrading via the '/opt/venv/bin/python -m pip install --upgrade pip' command.
 
#10 ERROR: executor failed running [/bin/bash -ol pipefail -c python -m venv /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt]: exit code: 1
-----
> [stage-0 6/9] RUN --mount=type=cache,id=s/d3b41cd2-3817-4a81-ba7d-ff021a7d5a6f-/root/.cache/pip,target=/root/.cache/pip python -m venv /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt:
-----
executor failed running [/bin/bash -ol pipefail -c python -m venv /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt]: exit code: 1
 
Error: Docker build failed

The error could be "Error: pg_config executable not found.", so I have looked up the error in Google, and I got that I have to change the library "psycopg2" to "psycopg2-binary", but I still get the same error.

After I tried a "template" in railway, which is like configurations for each framework, and it brings a sample app to test with, in this case, it was a Django app, in that app I saw that the dependency "psycopg2" was the version "2.8.6", and it was working, so I also replaced the version "2.9.3" to "2.8.6", but with the same result, even with replacing it with the dependency "psycopg2-binary".

This is the requirement.txt file:

asgiref==3.5.2
async-generator==1.10
attrs==21.4.0
backports.zoneinfo==0.2.1
beautifulsoup4==4.10.0
bleach==4.1.0
cached-property==1.5.2
certifi==2021.5.30
cffi==1.15.0
charset-normalizer==2.0.6
cloudinary==1.29.0
colorama==0.4.4
coverage==6.4.1
cryptography==36.0.1
dj-database-url==0.5.0
Django==4.0.4
django-environ==0.8.1
django-heroku==0.3.1
docutils==0.17.1
et-xmlfile==1.1.0
frozendict==2.0.6
genanki==0.11.0
h11==0.13.0
idna==3.2
importlib-metadata==4.8.1
keyring==23.2.1
numpy==1.22.3
openpyxl==3.0.9
outcome==1.1.0
packaging==21.0
pandas==1.4.2
pkginfo==1.7.1
psycopg2-binary==2.8.6
pycparser==2.21
Pygments==2.10.0
pyOpenSSL==22.0.0
pyparsing==3.0.0
pystache==0.6.0
python-dateutil==2.8.2
pytz==2022.1
pywin32-ctypes==0.2.0
PyYAML==5.4.1
readme-renderer==30.0
requests==2.26.0
requests-toolbelt==0.9.1
rfc3986==1.5.0
selenium==4.1.0
six==1.16.0
sniffio==1.2.0
sortedcontainers==2.4.0
soupsieve==2.2.1
sqlparse==0.4.2
tqdm==4.62.3
trio==0.19.0
trio-websocket==0.9.2
twine==3.4.2
tzdata==2022.1
urllib3==1.26.6
webencodings==0.5.1
whitenoise==6.2.0
wsproto==1.0.0
zipp==3.6.0

Is there some idea about what is happening?

Running johnnydep on your requirements.txt, shows that django-heroku depends on psycopg2 :

>>> johnnydep django-heroku
2022-07-19 17:03:28 [info     ] init johnnydist                [johnnydep.lib] dist=django-heroku parent=None
2022-07-19 17:03:30 [info     ] init johnnydist                [johnnydep.lib] dist=dj-database-url>=0.5.0 parent=django-heroku
2022-07-19 17:03:32 [info     ] init johnnydist                [johnnydep.lib] dist=django parent=django-heroku
2022-07-19 17:03:37 [info     ] init johnnydist                [johnnydep.lib] dist=psycopg2 parent=django-heroku
2022-07-19 17:03:45 [warning  ] Created temporary directory: /private/var/folders/0t/p6l6_9qd15bb9qx6bq2mrt1r0000gn/T/pip-ephem-wheel-cache-q2agslxa
....

Notes:
1.) I stopped after the first match (possibly there are more dependencies).
2.) I dont know if it is sufficient to put psycopg2-binary at the beginning of your requirements.txt, to prevent psycopg2 needed to get installed.

Deleting "django-heroku" from requirements.txt and also removing it from settings.py file solved my issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM