@spinlud (spinlud) posted a new topic, subject "Can't deploy to PyPI anymore: pkg_resources.ContextualVersionConflict: importlib-metadata 0.18". It read:

   Hi!  
    I am having problems deploying new package versions to PyPI:  
    https://travis-ci.com/github/spinlud/py-linkedin-jobs-scraper/jobs/430957329
    
    In the build I can see the following error (expanding `Deploying application`):
    [code] 
        Traceback (most recent call last):
          File "/home/travis/virtualenv/python3.6.7/bin/twine", line 8, in <module>
            sys.exit(main())
          File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/twine/__main__.py", line 28, in main
            result = cli.dispatch(sys.argv[1:])
          File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/twine/cli.py", line 80, in dispatch
            main = registered_commands[args.command].load()
          File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2446, in load
            self.require(*args, **kwargs)
          File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2469, in require
            items = working_set.resolve(reqs, env, installer, extras=self.extras)
          File "/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages/pkg_resources/__init__.py", line 775, in resolve
            raise VersionConflict(dist, req).with_context(dependent_req)
        pkg_resources.ContextualVersionConflict: (importlib-metadata 0.18 (/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages), Requirement.parse('importlib-metadata>=1; python_version < "3.8"'), {'keyring'})
        dist/linkedin-jobs-scraper-1.2.2.tar.gz already exists, no checkout
        linkedin_jobs_scraper.egg-info/PKG-INFO already exists, no checkout
        linkedin_jobs_scraper.egg-info/SOURCES.txt already exists, no checkout
        linkedin_jobs_scraper.egg-info/dependency_links.txt already exists, no checkout
        linkedin_jobs_scraper.egg-info/requires.txt already exists, no checkout
        linkedin_jobs_scraper.egg-info/top_level.txt already exists, no checkout
        error: could not restore untracked files from stash
        The stash entry is kept in case you need it again.
        PyPI upload failed.
        failed to deploy
        
    [/code]
    
    This line in particular states there is a version conflict:
    [code] 
        pkg_resources.ContextualVersionConflict: (importlib-metadata 0.18 (/home/travis/virtualenv/python3.6.7/lib/python3.6/site-packages), Requirement.parse('importlib-metadata>=1; python_version < "3.8"'), {'keyring'})
        
    [/code]
    
    but I am not sure how to solve this. I have no problems on building and uploading the package from local, this issue happens only with the Travis pipeline.
    
    This is the `.travis.yml`:
    [code] 
        sudo: required
        
        services:
          - docker
        
        language: python
        python:
          - '3.6'
        
        install:
          - pip install -r requirements.txt
        
        jobs:
          include:
            - stage: test
              script: ./tests/run_tests.sh
            - stage: deploy
              script:
                - python setup.py install_egg_info sdist bdist_wheel
              deploy:
                provider: pypi
                username: '__token__'
                password: $PYPI_TOKEN
                on:
                  branch: master
        
        stages:
          - test
          - deploy
        
    [/code]
    
    Anyone has any idea on how to fix this issue?

After which, @phantomas1234 (Nikolaus Sonnenschein) added

    travis-ci.org
    
    ### Travis CI - Test and Deploy Your Code with Confidence
    
    Same issue here, came out of the blue.

After which, @hugovk (Hugo) added

    Does it work using a new Python version than 3.6?

Then @BanzaiMan (Hiro Asari) said

    Try re-setting the deployment token. Perhaps it was not correctly migrated from .org to .com.

After which, @awcrosby (Andrew Crosby) added

    I ran into the same issue starting today (last deploy on 4 Nov was successful). Tried using both python 3.6 and 3.7.
    [code] 
        pkg_resources.ContextualVersionConflict: (importlib-metadata 0.18 (/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages), Requirement.parse('importlib-metadata>=1; python_version < "3.8"'), {'keyring'})
    [/code]

Then @masenf (Masen Furer) said

    The release of keyring 21.5.0 appears to have regressed travis-ci deploy functionality.
    
    I have worked around the issue temporarily by adding the following line to my deploy stage:
    
    `install: pip install keyring==21.4.0`

Then @hugovk (Hugo) said

    masenf:
    
    > The release of keyring 21.5.0  appears to have regressed travis-ci deploy functionality.
    
    In that diff, we can see the new keyring now requires `importlib_metadata >= 1`:
    [code] 
        -	importlib_metadata; python_version < "3.8"	
        +	importlib_metadata >= 1; python_version < "3.8"
        
    [/code]
    
    And from one of the above failing logs, the “Installing deploy dependencies” section says:
    [code] 
        keyring 21.5.0 requires importlib-metadata>=1; python_version < "3.8", but you'll have importlib-metadata 0.18 which is incompatible.
        
    [/code]
    
    So looks like one of the earlier dependencies is requiring importlib-metadata 0.18, and causing the problem. I don't know which one it is, but it'd be good to find out which one requirers that and loosen their pinning.
    
    `pip install pipdeptree && pipdeptree --reverse --packages importlib-metadata` could help.

So @native-api replied

    github.com/travis-ci/dpl
    
    ####  Fix Pip not updating outdated dependency if it's preinstalled
    
    `travis-ci:v1` ← `native-api:pip_fix_upgrade_deps`
    
    opened 02:14PM - 10 Nov 20 UTC
    
    native-api 
    
    +2 -1
    
    @spinlud et al, please test this fix by adding the following to the `deploy:` entry:
    [code] 
        edge:
           source: 'native-api/dpl'
           branch: 'pip_fix_upgrade_deps'
        
    [/code]

After which, @spinlud (spinlud) added

    Updated with the following and it worked!
    [code] 
        sudo: required
        
        services:
          - docker
        
        language: python
        python:
          - '3.6'
        
        install:
          - pip install -r requirements.txt
        
        jobs:
          include:
            - stage: test
              script: ./tests/run_tests.sh
            - stage: deploy
              script:
                - python setup.py install_egg_info sdist bdist_wheel
              deploy:
                provider: pypi
                username: '__token__'
                password: $PYPI_TOKEN
                on:
                  branch: master
                edge:
                  source: 'native-api/dpl'
                  branch: 'pip_fix_upgrade_deps'
        
        stages:
          - test
          - deploy
        
    [/code]

@cmohl2013 (Christoph Moehl) replied

    @native-api Thank you, this works!

So @achantavy (Alex Chantavy) replied

    Once https://github.com/travis-ci/dpl/pull/1221 is merged, will I need to remove
    [code] 
        edge:
           source: 'native-api/dpl'
           branch: 'pip_fix_upgrade_deps'
        
    [/code]
    
    from my `deploy:` entry?

@jvasallo (Joel Vasallo) replied

    Running into the same issue on our repo, using the same edge branch solved it for us.  
    
    
    github.com
    
    #### foremast/foremast/blob/master/.travis.yml#L48
    [code]     
          38.     
          39. - provider: pypi
          40.   username: foremast-deployer
          41.   password:
          42.     secure: UfsQ12Ox1wB5nWSIC26zJle2a3TM+agVkHjCV9y1z7DUMhvQgSx05M9cWL8ZsAQBGhjeF8HPwgxTxg9Kr3ayR4m/BuQIztsahiMhg1DK3taOEla+WcT3/+EVPgGwn5w91Vntn3S4j4f7Ym8WqDdI/o0m/Bn6Lt6Cx/dPXTskhNXp/SaHW/Xd6r32objsD4UqKRVOb/WGFtDfDypZc/Uz1aXkaFCR8CFzebxWh3eKWhdgJE5x13bNEPDUz3X1Al872SSF/3vQ8H2rtZxtODROPjaxNrrTKdEh9f4/q5NHWxyEuyViBk7YHdzuZxinHScxFv3roBy29jl+qSzZgdTNYBKeMp7YJqiOshgCUFLPQHTHZyUpb3E/ELAC2ULJOwD+Wz5Fo84gVFwUNu5I7qQiWeQa4+9y0qjpGFFGLNf5GspUpBY8dzkF9ZjPadpmWfU2IaMIYQ7W3fojz8ok8jZ2CCrXiZEm400WRewI7SIqLmBZZAIZ08yJSyTTJgH32YfeVCBKGkiRVd1U4H4xTnxaghrRktC3M3NZgbxpUosiQY6k2k85I6J0jv5Q12k+mi5sU6G3z36ZPeu4+gGNqCERbwVK2aITQDh5HC/tw++FLyxTwZ0l5xahWHzxgwobplbk18bcAUdoPmgDT0w9x0zeRwfdY5S9RwfAakYPDMB02dE=
          43.   distributions: bdist_wheel
          44.   on:
          45.     condition: $TOXENV = lint
          46.     tags: true
          47.   edge:
          48.     source: 'native-api/dpl'
          49.     branch: 'pip_fix_upgrade_deps'
          50.     
          51. notifications:
          52.   webhooks:
          53.     urls: https://webhooks.gitter.im/e/a57f158d4365b3598713
          54.     on_success: never
          55.     on_failure: always
          56.     on_start: never
          57.   58. cache: false
        
        
        
    [/code]
    
    Unfortunately we have to retain support for this version, but thanks for your contribution!
    
    Adding as watcher so I know when I can remove

To which @native-api replied

    The deployment logic generates a new unique succeeding version number (quite a tricky thing to do with Git) without needing a tag. So merging the PR is enough. I didn't know that, that's very smart, @BanzaiMan !
    
    @spinlud et al, anyway, you can remove the workaround now!

Then @spinlud (spinlud) said

    @native-api good to know, thanks for the support!

After which, @RhinosF1 (Rhinos F1) added

    I still encountered this today following https://github.com/MirahezeBots/MirahezeBots/commit/5f54eaf2dc570a514663d065cc46397d0840f70e
    
    Adding https://github.com/MirahezeBots/MirahezeBots/commit/3b26c41ff3e036684089f03ecb8b42f4530a2b55 fixed this
    
    But my understanding was the PR was merged so it shouldn't have been an issue?

@shcheklein (Ivan Shcheklein) replied

    Same is happening for us. Temporary workaround is not available since that branch got merged or deleted?
    
    travis-ci.com
    
    ### Travis CI - Test and Deploy with Confidence

Then @steveyang90 (Steve Yang) said

    I also encountered the same today after @native-api's branch was merged. One workaround is to opt-in to dpl v2 by adding the following to travis configs
    [code] 
        deploy:
         provider: <provider>
         # ⋮
         edge: true
        
    [/code]
    
    Example of failing deployment followed by passing deployment after adding `edge: true`

To which @native-api replied

    Okay, I see. Gems automatically uploaded upon merges into `v1` are considered prereleases.  
    @BanzaiMan So you do need to create a new release – or we need to supply `--pre` to `gem install` in the deployment logic. See https://github.com/travis-ci/travis-build/pull/1972 .

@pedrobern (pedrobern) replied

    [code]
        deploy:
         provider: <provider>
         # ⋮
         edge: true
        
    [/code]
    
    This worked for me.

After which, @BanzaiMan (Hiro Asari) added

    We have deployed `dpl` 1.10.16, so `edge` should no longer be necessary.

After which, @rmk135 (Roman Mogylatov) added

    Hey everybody,
    
    I face this issue on .com. Did anyone ported / deployed the fix to .com?
    
    Here is the broken build https://travis-ci.com/github/ets-labs/python-dependency-injector/jobs/455057934. Fails on last command even thus it's green.

@rmk135 (Roman Mogylatov) replied

    If anyone still faces the issue and looks for the fix, you can install twine with next options:
    
    `python -m pip install --upgrade --upgrade-strategy eager twine`
    
    As state above, it will will resolve the dependencies proper way.

Then @native-api said

    @rmk135 The fix is for the stock PyPI deployer. You are not using it but rather deploying things yourself.

@rmk135 (Roman Mogylatov) replied

    @native-api, got it, thanks. So it's not Travis issue, but more pip / twine / keyring problem, correct?

So @native-api replied

    @rmk135 Pip problem. It doesn't properly update a dependency when it's installed but some of the other packages requires a newer version. Apart from `--upgrade-strategy eager`, using the new resolver may help (with `--use-feature=2020-resolver` or by using Pip 20.3+).


{'source': 'discourse', 'url': 'https://travis-ci.community/t/cant-deploy-to-pypi-anymore-pkg-resources-contextualversionconflict-importlib-metadata-0-18/10494', 'title': "Can't deploy to PyPI anymore: pkg_resources.ContextualVersionConflict: importlib-metadata 0.18", 'views': 5956, 'has_accepted_answer': True, 'word_count': 1490, 'like_count': 18, 'reply_count': 15, 'participant_count': 15, 'posts': 25, 'tags': 'bug pypi', 'author': '@spinlud (spinlud)', 'participants': '@spinlud (spinlud), @phantomas1234 (Nikolaus Sonnenschein), @hugovk (Hugo), @BanzaiMan (Hiro Asari), @awcrosby (Andrew Crosby), @masenf (Masen Furer), @native-api, @cmohl2013 (Christoph Moehl), @achantavy (Alex Chantavy), @jvasallo (Joel Vasallo), @RhinosF1 (Rhinos F1), @shcheklein (Ivan Shcheklein), @steveyang90 (Steve Yang), @pedrobern (pedrobern), @rmk135 (Roman Mogylatov)', 'image_url': [None], 'created_at': '2020-11-09T09:03:49.044Z', 'last_posted_at': '2020-12-12T12:14:14.587Z'}