user218592
user218592

Reputation: 57

Poetry and Vercel issue

I have found out about Poetry recently, and I am amazed by how well it works compare to the regular pip and whatnot. But I am facing issues with when I try to host my Django app on Vercel. Since Vercel have no functionality of poetry I cannot host my django over there.

I have tried chatgpt and the solution is to modify the vercel.json file which I did.

{
  "build": {
    "env": {
      "POETRY_VERSION": "1.1.4"
    }

  },
  "builds": [
    {
      "src": "test/wsgi.py",
      "use": "@vercel/python",
      "config": {
        "maxLambdaSize": "15mb", 
        "runtime": "python3.9"
      }
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "test/wsgi.py"
    }
  ]
}

but then I got these errors.

[ERROR] Runtime.ImportModuleError: Unable to import module 'vc__handler__python': No module named 'django'

then I tried this solution vercel-poetry but when I followed this solution my app would not even deploy it would give error even the building part

Error: Command failed: python3.9 -m poetry export --without-hashes -f requirements.txt --output requirements.txt

and

ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2k-fips 26 Jan 2017'. See: https://github.com/urllib3/urllib3/issues/2168 so after exhausting everything that I could am here for help.

Upvotes: 1

Views: 1125

Answers (2)

SoSaymon
SoSaymon

Reputation: 61

Since @XAX's answer didn't work for me I found that poetry has its own "poetry-to-pip" like converter. You can just enter into your CLI poetry run pip freeze > requirements.txt command. (Un)fortunetly that will convert your dev-dependencies too.

Upvotes: 1

XAX
XAX

Reputation: 48

Your dependencies aren't installed. Vercel needs a requirements.txt in the root of your project to install dependencies correctly. You can manage your deps using poetry locally but you do need a requirements.txt

You can automate the process of running poetry export --without-hashes > requirements.txt every time you make a commit by using Git hooks. Git hooks are scripts that run automatically at certain points in the Git workflow.

Here's how you can set up a Git hook to run the poetry export command:

  1. Navigate to the root directory of your Git repository.

  2. Create a new file named pre-commit in the .git/hooks directory. If the pre-commit file already exists, open it for editing.

  3. Add the following code to the pre-commit file:

#!/bin/bash

# Run poetry export command
poetry export --without-hashes > requirements.txt

# Stage the updated requirements.txt file
git add requirements.txt
  1. Save the pre-commit file and exit the editor.

  2. Make the pre-commit file executable by running the following command:

chmod +x .git/hooks/pre-commit

Now, every time you make a commit, the pre-commit hook will automatically run the poetry export command and update the requirements.txt file. The updated requirements.txt file will be staged for commit along with your other changes.

Please note that this approach assumes you have poetry installed and configured correctly on your local machine.This will update your requirements.txt and stage it each time you make a commit.

Upvotes: 3

Related Questions