hg-git "abort: No module named selectors!"

Create issue
Issue #5140 open
vitidev created an issue

any operation with any github repository cause error abort: No module named selectors!

Tortoise 4.6.1, Win 10 x64 1079, all extenisons (except hg-git of course) disabled

% hg clone --verbose https://github.com/BerndSchrader/VisualHG.git "c:\dev\forks\CsConsoleFormat"
abort: No module named selectors!
[command returned code 255 Mon Jul 23 13:33:21 2018]

Comments (52)

  1. Yuya Nishihara
    • changed status to open

    @sborho So, hggit or dulwich start depending on the selectors module of Python 3?

    Can you show a backtrace to be displayed with hg clone --traceback ...?

  2. vitidev reporter
    $ hg clone --verbose --traceback https://github.com/BerndSchrader/VisualHG.git "c:\dev\forks\CsConsoleFormat"
    Traceback (most recent call last):
      File "mercurial\scmutil.pyo", line 160, in callcatch
      File "mercurial\dispatch.pyo", line 341, in _runcatchfunc
      File "mercurial\dispatch.pyo", line 971, in _dispatch
      File "mercurial\dispatch.pyo", line 727, in runcommand
      File "mercurial\dispatch.pyo", line 979, in _runcommand
      File "mercurial\dispatch.pyo", line 968, in <lambda>
      File "mercurial\util.pyo", line 1553, in check
      File "mercurial\commands.pyo", line 1467, in clone
      File "mercurial\hg.pyo", line 709, in clone
      File "hggit\util.pyo", line 60, in inner
      File "hggit\__init__.pyo", line 388, in exchangepull
      File "hggit\git_handler.pyo", line 280, in fetch
      File "hggit\git_handler.pyo", line 1220, in fetch_pack
      File "hggit\git_handler.pyo", line 1764, in get_transport_and_path
      File "dulwich\client.pyo", line 1330, in __init__
      File "dulwich\client.pyo", line 1304, in default_urllib3_manager
      File "hgdemandimport\demandimportpy2.pyo", line 167, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
      File "urllib3\__init__.pyo", line 8, in <module>
      File "hgdemandimport\demandimportpy2.pyo", line 243, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
      File "urllib3\connectionpool.pyo", line 29, in <module>
      File "hgdemandimport\demandimportpy2.pyo", line 243, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
      File "urllib3\connection.pyo", line 39, in <module>
      File "hgdemandimport\demandimportpy2.pyo", line 243, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
      File "urllib3\util\__init__.pyo", line 3, in <module>
      File "hgdemandimport\demandimportpy2.pyo", line 243, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
      File "urllib3\util\connection.pyo", line 3, in <module>
      File "hgdemandimport\demandimportpy2.pyo", line 243, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
      File "urllib3\util\wait.pyo", line 1, in <module>
      File "hgdemandimport\demandimportpy2.pyo", line 243, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
    ImportError: No module named selectors
    abort: No module named selectors!
    
  3. Simon Bosanquet

    Any movement on this?

    I have come across the same issue when trying to use hg push to a remote git repo. The traceback reads the same but I thought I should post it anyway:

    hg push origin --verbose --traceback
    finding hg commits to export
    Traceback (most recent call last):
      File "mercurial\scmutil.pyo", line 160, in callcatch
      File "mercurial\dispatch.pyo", line 341, in _runcatchfunc
      File "mercurial\dispatch.pyo", line 971, in _dispatch
      File "mercurial\dispatch.pyo", line 727, in runcommand
      File "mercurial\dispatch.pyo", line 979, in _runcommand
      File "mercurial\dispatch.pyo", line 968, in <lambda>
      File "mercurial\util.pyo", line 1553, in check
      File "mercurial\util.pyo", line 1553, in check
      File "hgext\mq.pyo", line 3599, in mqcommand
      File "mercurial\util.pyo", line 1553, in check
      File "mercurial\commands.pyo", line 4216, in push
      File "hggit\util.pyo", line 60, in inner
      File "hggit\__init__.pyo", line 421, in exchangepush
      File "hggit\git_handler.pyo", line 413, in push
      File "hggit\git_handler.pyo", line 1070, in upload_pack
      File "hggit\git_handler.pyo", line 1764, in get_transport_and_path
      File "dulwich\client.pyo", line 1330, in __init__
      File "dulwich\client.pyo", line 1304, in default_urllib3_manager
      File "hgdemandimport\demandimportpy2.pyo", line 167, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
      File "urllib3\__init__.pyo", line 8, in <module>
      File "hgdemandimport\demandimportpy2.pyo", line 243, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
      File "urllib3\connectionpool.pyo", line 29, in <module>
      File "hgdemandimport\demandimportpy2.pyo", line 243, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
      File "urllib3\connection.pyo", line 39, in <module>
      File "hgdemandimport\demandimportpy2.pyo", line 243, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
      File "urllib3\util\__init__.pyo", line 3, in <module>
      File "hgdemandimport\demandimportpy2.pyo", line 243, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
      File "urllib3\util\connection.pyo", line 3, in <module>
      File "hgdemandimport\demandimportpy2.pyo", line 243, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
      File "urllib3\util\wait.pyo", line 1, in <module>
      File "hgdemandimport\demandimportpy2.pyo", line 243, in _demandimport
      File "hgdemandimport\demandimportpy2.pyo", line 41, in _hgextimport
    ImportError: No module named selectors
    abort: No module named selectors!
    
  4. Evgeny Vrublevsky

    I also have encountered this issue. I'm ready to provide anything what is required to fix it.

  5. Pintér Gábor

    This bug is present in versions 4.7.0, 4.6.1 and 4.5.3 too, but not in 4.0.0. As an emergency measure I rolled back to the really old 4.0.0.

  6. Matt Wilkie
    $ hg clone --verbose https://github.com/leo-editor/leo-editor.git "D:\code-maphew"
    ** Unknown exception encountered with possibly-broken third-party extension hggit
    ** which supports versions 4.7 of Mercurial.
    ** Please disable hggit and try your action again.
    ** If that fixes the bug please report it to https://bitbucket.org/durin42/hg-git/issues
    ** Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]
    ** Mercurial Distributed SCM (version 4.8)
    ** Extensions loaded: githelp, hggit
    Traceback (most recent call last):
      File "hg", line 50, in <module>
      File "mercurial\dispatch.pyo", line 96, in run
      File "mercurial\dispatch.pyo", line 220, in dispatch
      File "mercurial\dispatch.pyo", line 363, in _runcatch
      File "mercurial\dispatch.pyo", line 371, in _callcatch
      File "mercurial\scmutil.pyo", line 166, in callcatch
      File "mercurial\dispatch.pyo", line 354, in _runcatchfunc
      File "mercurial\dispatch.pyo", line 994, in _dispatch
      File "mercurial\dispatch.pyo", line 737, in runcommand
      File "mercurial\dispatch.pyo", line 1003, in _runcommand
      File "mercurial\dispatch.pyo", line 991, in <lambda>
      File "mercurial\util.pyo", line 1644, in check
      File "mercurial\commands.pyo", line 1557, in clone
      File "mercurial\hg.pyo", line 536, in clone
      File "hggit\__init__.pyo", line 344, in peer
      File "mercurial\hg.pyo", line 200, in peer
      File "mercurial\hg.pyo", line 161, in _peerorrepo
    TypeError: __init__() got an unexpected keyword argument 'createopts'
    
  7. muxator

    @pintergabor, that one is a different issue, I guess.

    This one ("no module named selectors") is maybe still broken in the Windows package (I do not use it). At least on linux, I have no problems working with github. It is indeed my main workflow nowadays.

  8. Neven Boyanov

    I am using TortoiseHg version 4.8.1 on Windows and the issue is still present.

    Is this, as pointed out above, dependency on a Python 3.x module?

  9. Александр Литягин

    I am using TortoiseHg version 4.8.1 on Windows and the issue is still present.

    +1

  10. kankri

    This problem seems to affect HTTP URLs only, I usually work with git+ssh URLs and hadn't noticed the problem before.

    I worked around the issue in THG 4.6.1 by expanding library.zip:

    > cd C:\Program Files\TortoiseHg\lib
    > ren library.zip library.zip.orig
    > 7z.exe x -olibrary.zip library.zip.orig
    

    And then adding the missing selectors.py file. I have earlier done pip install --user urllib3 so I could do:

    > cd library.zip\urllib3
    > copy C:\Users\user\AppData\Roaming\Python\Python27\site-packages\urllib3\util\selectors.py util
    

    Alternatively I could have copied the full urllib3 directory tree into library.zip to be sure there is no compatibility problem. And of course you could install urllib3 into a temporary virtualenv and grab the files from there (virtualenv tempve & tempve\scripts\pip install urllib3).

    After this I got a problem that hggit failed to connect to Github with SSL. I didn't bother to analyze what caused that, instead I made THG use an external hggit and dulwich and things started working. Another approach would have been to copy also those packages into library.zip.

  11. Fabrice Frebel

    I'm a little bit confused by the proposed workaround. In my understanding, the current version of Mercurial is compatible with Python 2.7 and the "selector.py" file is only distributed with Python 3. Right?

  12. vitidev reporter
    1. c:\Program Files\TortoiseHg\lib\library.zip\urllib3\utils\ does not contains file "selectors.py(o)"
    2. https://github.com/urllib3/urllib3/tree/master/src/urllib3/util (and https://pypi.org/project/urllib3/) does not contains file "selectors.py(o)"
    3. pip install --user urllib3 on python 2.7 (win 10 & ubuntu 16.04) install urllib3 version without "selectors.py"
    4. python 3+ has "Lib/selectors.py", but TortoiseHg is compatible with Python 2.7

    where is "selectors.py"?

    I found it there but where to find the complete package?! Then I found "utils\selectors.py" in https://github.com/urllib3/urllib3 in revision range 3366 - 3404

    I replaced library.zip\urllib3 with revision 3366 and got another error

    urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=u'github.com', port=443): Max retries exceeded with url: ***.git/info/refs?service=git-upload-pack (Caused by SSLError(IOError(2, 'No such file or directory'),))
    

    Also I total replaced library.zip\urllib3 with latest urllib3 and got same error

    ps: I tried replace library.zip\hggit and library.zip\dulwich but it gave nothing

  13. vitidev reporter

    hggit requires urllib2 dulwich requires urllib3 and something goes wrong

    replace c:\Program Files\TortoiseHg\lib\library.zip\dulwich (4.9.0) with library.zip\dulwich from 4.5.2 (where old dulwich based on urllib2) and it work.

    Of course this is not the latest dulwich version, but the same version we use in Tortoise 4.5.2, which we are forced to use

  14. kankri

    @vitidev: Sorry, didn't see your comments earlier. Indeed, now that I check the path selectors.py isn't there any more! I see from the time stamps that some installation has updated the urllib3 dependency after I wrote the comment.

    Looking at urllib3 commit history it seems the file was deleted in this commit. Looking at this page it seems version 1.22 is the last one before that commit. Therefore you can get the now missing file by:

    >virtualenv venv
    >venv\Scripts\pip.exe install urllib3==1.22
    >copy venv\lib\site-packages\urllib3\util\selectors.py ...
    

    This is still a crude hack, but helped me last month when I had to clone from Github with HTTPS protocol. I saw you also managed to get past that error to the next. Like I mentioned, I use externally checked out hggit and dulwich. Don't know why that didn't help you, but good to know you got it working by taking the old version.

    The root cause seems to be a packaging problem which shouldn't be that difficult to fix...

  15. vitidev reporter

    I did it (but not the first time, mystic)

    1. unpack library.zip
    2. replace urllib3 with same content from https://pypi.org/project/urllib3/
    3. replace hg-git with same content from https://bitbucket.org/durin42/hg-git/
    4. replace dulwich with same content from https://github.com/dulwich/dulwich/

    But I got error when try to push

    abort: git remote error: unexpected http resp 401 for https://.../info/refs?service=git-receive-pack
    

    I found the issue and applied solution by Dmitriy Ivanov (replace library.zip/hg-git/git_handler.py with pached content

    and it works!

  16. vitidev reporter

    v 4.9.1 windows 10. The issue is still present. solution: perform steps 1-4 in the message above

    try clone any repo

    if get error "Max retries exceeded with url" - additionally remove library.zip/certifi

  17. Matt Wilkie

    The fix appears to be identified, what needs to happen to finish this off? (where can a volunteer step in and do something useful?)

  18. muxator

    @maphew , @vitidev : maybe it makes sense to close this issue and open a more specific one?

    Looking at thg-winbuild 6b655b (last commit as of today), I think that thg 5.0 will bundle a recent hg-git version (5d688b).

    The original problem indicated in this issue (no modules named selectors) had to do with a compatibility problem between old hg-git versions and mercurial 4.8. That problem was fixed in hg-git ae6b1ba74829, which was already included in TortoiseHg 4.9 (you can always look at the extension-versions.txt file in thg-winbuild repository).

    Indeed, @vitidev debugging seems to indicate a packaging problem with urllib. Maybe opening a new issue to try to fix this would help making progress. TortoiseHg 5.0 is going to be released soon and it would be good to have a working windows build.

    Disclaimer: I am not a Windows user and I do not maintain thg, so I may perfectly be wrong.

  19. Дмитрий Иванов

    I have created the patch for the TortoiseHG 4.9.1 that makes hg-git works!

    https://bitbucket.org/dmitriyse/hg-git/downloads/TortoiseHg491-hggit-patch.zip

    Patched things:

    1. Updated dulwich ( 0.19.11)
    2. Updated hg-git (to this this revision https://bitbucket.org/dmitriyse/hg-git-git/commits/e6fceee89209e9a5249e07125937324041e33a13)
    3. Updated certifi ( 2019.3.9) + patch core.py “return os.path.join(f, 'cacert.pem')“ ---> “return os.path.join(f, '../..', 'cacert.pem')”
    4. Updated urllib3 ( 1.24.1)

    Extract two files from the TortoiseHg491-hggit-patch.zip to your installation of the TortoiseHG 4.9.1 x64 (Typically c:\Program Files\Tortoise HG”)

    Happy times back!

  20. Divi Lainé

    Thank you so much @dmitriyse ! it works like a charm.

    very easy, just 2 files to replace and it rocks

  21. Peter Suter

    @Yuya Nishihara Can the patch above be included in the next release? Or what is needed to make it happen? Is it just a matter of someone sending a PR, or is there a fundamental problem with the fix? Thanks all.

  22. vitidev reporter

    v 5.0.2 windows 10. The issue is still present.

    Again have to pick up working versions of extensions 🙁

    @Peter Suter Just need to use no older versions hg-git/dulwich/urllib3 (and fix certificate path)
    Why developers of TortoiseHg don't update this packages? - I don't know

  23. Matt Harbison

    @Peter Suter - yes, that needs to be updated. There’s also a dulwich reference in setup.py- I didn’t check to see which take priority.

  24. vitidev reporter

    For those who do not want to wait

    For Tortoise Hg 5.0.2 the solution is the same

    1. unpack library.zip
    2. replace urllib3 with 1.24.1 (in newer versions there is a dependence on brotli, but we do not need it)
    3. replace hg-git with same content from [https://bitbucket.org/durin42/hg-git/](https://bitbucket.org/durin42/hg-git/)
    4. replace dulwich with same content from https://github.com/dulwich/dulwich/ (latest 0.19.11)

    dulwich, urllib3, may be taken from patch of @Дмитрий Иванов

    But not hggit, because there will be a error with function ‘memfilectx()’ and ‘memctx()’.

    Original hg-git repo has commits for this function from muxator, apparently for this reason it works.

    So we have to use the original [https://bitbucket.org/durin42/hg-git/](https://bitbucket.org/durin42/hg-git/)


    We get the same errors:

    urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=u'github.com', port=443): Max retries exceeded with url

    remove certifi or use certifi from patch

    abort: git remote error: unexpected http resp 401 for https://.../info/refs?service=git-receive-pack

    modify library.zip/hg-git/git_handler.py as there https://bitbucket.org/durin42/hg-git/pull-requests/67/fix-for-dulwich-0190-authentication-error/diff

  25. Alexander Leschinsky

    @Matt Harbison - due to my (very) limited capabilities I still use dirty hack, suggested above by Дмитрий Иванов - replace in distro library.zip certifi+dulwich+urllib3 by patched versions from it’s archive. It worked in 4.9.1, it work now in my 5.0.2 (without touching hg-git)

  26. Alexander Leschinsky

    Sorry, but for library.zip from G-Drive I got

    You need permission

    Want in? Ask for access, or switch to an account with permission

  27. Siobhan Rohlwink-Coutts

    I used the patch and that sort of worked but for some reason it not carry over any of my seperate branches. Can anyone tell me why that is and how do i fix that

  28. Log in to comment