Score:0

ImportError: No module named 'pip._vendor.packaging'

in flag

I need to get some software running on Python 3.5

I am using Ubuntu 21.10.

I get this error:

(foobar_addressbook) guettli@p15:~/foobar/projects/foobar_addressbook$ tox -e py35-django18 


py35-django18 create: /home/guettli/foobar/projects/foobar_addressbook/.tox/py35-django18
ERROR: invocation failed (exit code 1), logfile: /home/guettli/foobar/projects/foobar_addressbook/.tox/py35-django18/log/py35-django18-1.log
==================================================================== log start =====================================================================
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/guettli/foobar/projects/foobar_addressbook/.tox/py35-django18/lib/python3.5/site-packages/pip/__main__.py", line 23, in <module>
    from pip._internal.cli.main import main as _main  # isort:skip # noqa
  File "/home/guettli/foobar/projects/foobar_addressbook/.tox/py35-django18/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/home/guettli/foobar/projects/foobar_addressbook/.tox/py35-django18/lib/python3.5/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/home/guettli/foobar/projects/foobar_addressbook/.tox/py35-django18/lib/python3.5/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "/home/guettli/foobar/projects/foobar_addressbook/.tox/py35-django18/lib/python3.5/site-packages/pip/_internal/cli/cmdoptions.py", line 23, in <module>
    from pip._vendor.packaging.utils import canonicalize_name
ImportError: No module named 'pip._vendor.packaging'

===================================================================== log end ======================================================================
_____________________________________________________________________ summary ______________________________________________________________________
ERROR:   py35-django18: InvocationError for command /home/guettli/foobar/projects/foobar_addressbook/.tox/py35-django18/bin/python -m pip freeze (exited with code 1)

Any idea how I can fix this error?

Related question: Segmentation fault while installing Python 3.5: ensurepip

Score:0
in flag

Step 1

pip in the virtualenv seems broken, so bootstrap pip:

curl  https://bootstrap.pypa.io/pip/3.5/get-pip.py | .tox/py35-django18/bin/python - 

Step 2

Now I get this error

    ERROR: Command errored out with exit status 1:
     command: /home/guettli/foobar/projects/foobar_addressbook/.tox/py35-django18/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-xsbc7r69/django-celery_63fa83d5391f499a9cc375c1c1fed8b6/setup.py'"'"'; __file__='"'"'/tmp/pip-install-xsbc7r69/django-celery_63fa83d5391f499a9cc375c1c1fed8b6/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-6esk_zf9
         cwd: /tmp/pip-install-xsbc7r69/django-celery_63fa83d5391f499a9cc375c1c1fed8b6/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/guettli/foobar/projects/foobar_addressbook/.tox/py35-django18/lib/python3.5/site-packages/setuptools/__init__.py", line 18, in <module>
        import setuptools.version
      File "/home/guettli/foobar/projects/foobar_addressbook/.tox/py35-django18/lib/python3.5/site-packages/setuptools/version.py", line 1, in <module>
        import pkg_resources
    ImportError: No module named 'pkg_resources'

To fix this:

.tox/py35-django18/bin/python -m pip install -U setuptools

Now the virtualenv of tox is working.

If you know an easier way to get Python3.5 working on Ubuntu 21.10, please leave a comment. Thank you.

ru flag
The way to get Python ancient working on ubuntu 21.10 is to use PyENV to set it up, or make sure you install PIP with your python compilation (not a default!) - this also makes setuptools and other things available in your environment by default.
guettli avatar
in flag
@ThomasWard I tried pyenv first, but it failed with a seg fault. See https://askubuntu.com/questions/1376525/segmentation-fault-while-installing-python-3-5-ensurepip
ru flag
May I ask why you *need* Python 3.5 which is many years old now? Is updating your application for newer python not doable for some reason?
guettli avatar
in flag
@ThomasWard Python3.5 is an intermediate step to get from 2.7 to 3.8. (This django app is using Django 1.4 at the moment).
ru flag
As someone who's had to move from Django old to Django latest your 'intermediate' step is likely to cause you more grief than a total rewrite. Because then you have to rewrite again to get to an even newer Django that is py3.8 compatible.
guettli avatar
in flag
@ThomasWard I don't want to use PyENV. It does magic things which I don't want to be done. For example it changes PATH and it needs to be enabled via .profile. All I want is `/usr/local/bin/python3.5`. I don't need a tool to switch between Python versions.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.