2

i use pipreqs to generate requirements.txt, the generated requirements.txt has a library GitPython with two versions 3.1.31 and 3.1.32

my command is python3 -m pipreqs.pipreqs $BASEDIR --force

log is:

WARNING: Import named "GitPython" not found locally. Trying to resolve it at the PyPI server.
WARNING: Import named "GitPython" was resolved to "GitPython:3.1.32" package (https://pypi.org/project/GitPython/).
Please, verify manually the final list of requirements.txt to avoid possible dependency confusions.
WARNING: Import named "Requests" not found locally. Trying to resolve it at the PyPI server.
WARNING: Import named "Requests" was resolved to "requests:2.31.0" package (https://pypi.org/project/requests/).
Please, verify manually the final list of requirements.txt to avoid possible dependency confusions.
INFO: Successfully saved requirements file in ./requirements.txt

generate file is:

GitPython==3.1.31
GitPython==3.1.32
oss2==2.17.0
Requests==2.31.0

when i run install command pip3 install -r ./requirements.txt

i got this error message:

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: GitPython==3.1.31 in /Users/tian/Library/Python/3.8/lib/python/site-packages (from -r ./requirements.txt (line 1)) (3.1.31)
ERROR: Cannot install GitPython==3.1.31 and GitPython==3.1.32 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested GitPython==3.1.31
    The user requested GitPython==3.1.32

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

is there a way to generate requirement.txt without conflict versions, if not i'll have to remove the conflict version manually

Jade
  • 416
  • 5
  • 7
  • 1
    i find a way to avoid this issue, after generate requirements, i delete its version and repeated library by script, and it become to `GitPython oss2 Requests`, now it works – Jade Jul 28 '23 at 08:08
  • I am having the same issue, but I didn't quite understand your solution. Did you just manually delete one of the GitPython entries? How did you know which one to delete? – Ricardo Corrales Barquero Aug 17 '23 at 01:12
  • @RicardoCorralesBarquero i delete it by python script, I've listed the code in my answer below – Jade Aug 24 '23 at 02:56

1 Answers1

0

this is my solution, I delete the repeated dependency versions by python script, this is my code

#!/usr/bin/python3

import os
import sys
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
code = os.system('python3 -m pipreqs.pipreqs %s --force' % SCRIPT_DIR)
if code != 0:
    sys.exit(code)

REQUIREMENTS_FILE = os.path.join(SCRIPT_DIR, 'requirements.txt')
if not os.path.exists(REQUIREMENTS_FILE):
    print('REQUIREMENTS not exists   ' + REQUIREMENTS_FILE)
    sys.exit(1)

deps = []
with open(REQUIREMENTS_FILE) as readfile:
            for line in readfile:
                key, value = line.partition("==")[::2]
                if key not in deps:
                     deps.append(key)
with open(REQUIREMENTS_FILE, 'w') as writefile:
    for l in deps:
        writefile.write(l)
        writefile.write('\n')
    writefile.flush()
    writefile.close()
print('success deps: ' + str(deps))

then the generated requirements.txt become

GitPython
oss2
Requests
Jade
  • 416
  • 5
  • 7