pythonpython-2.7scrapypython-wheelpython-importlib

ImportError: No module named importlib


I'm trying to install scrapy on python 2.7. The problem is that when it's time to compile it I get this error

$ sudo python2 -m pip install scrapy
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.                                                                              
Collecting scrapy
  Using cached Scrapy-1.8.3-py2.py3-none-any.whl (239 kB)
Collecting w3lib>=1.17.0
  Using cached w3lib-1.22.0-py2.py3-none-any.whl (20 kB)
Collecting parsel>=1.5.0
  Using cached parsel-1.6.0-py2.py3-none-any.whl (13 kB)
Collecting service-identity>=16.0.0
  Using cached service_identity-21.1.0-py2.py3-none-any.whl (12 kB)
Collecting lxml>=3.5.0
  Using cached lxml-4.9.3-cp27-cp27mu-manylinux_2_5_x86_64.manylinux1_x86_64.whl (5.7 MB)
Collecting PyDispatcher>=2.0.5
  Using cached PyDispatcher-2.0.7.tar.gz (38 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python2 /usr/local/lib/python2.7/dist-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpYKy7qC                                                                                       
       cwd: /tmp/pip-install-oJOx4o/pydispatcher                                                                    
  Complete output (4 lines):                                                                                        
  Traceback (most recent call last):                                                                                
    File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/pep517/_in_process.py", line 16, in <module>           
      from importlib import import_module                                                                           
  ImportError: No module named importlib                                                                            
  ----------------------------------------                                                                          
ERROR: Command errored out with exit status 1: /usr/bin/python2 /usr/local/lib/python2.7/dist-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpYKy7qC Check the logs for full command output.  

but i have already installed importlib

$ sudo python2 -m pip install importlib          
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.                                                                              
Requirement already satisfied: importlib in /usr/local/lib/python2.7/dist-packages (1.0.4)

I tried installing importlib2 too (which is the older version of importlib for Python 2.7), but the same error is thrown.


Solution

  • If you only need to install Scrapy, you will likely need to download the files from Github here: Github - Scrapy. This is one way to download it:

    1. Click on 'number Commits' and scroll down to the bottom.

    2. Click on 'Older' until you find a version old enough to satisfy Python 2.7's syntax rules. Open it in your browser.

    3. Look for the commit id. It will look something like this: 'commit a1bc23'.

    4. Open up your terminal. Copy and paste (ctrl + shift + v) these commands:

      A. git clone git://github.com/scrapy/scrapy (append .git to the end if that doesn't work)

      B. cd scrapy

      C. git checkout YOUR_COMMMIT_ID_HERE

      D. git export.

    5. Then, cut and paste from the folder it saved to into '/usr/local/lib/python2.7/site-packages' and extract into a folder named 'scrapy' if it doesn't already put it in a folder under that name. You should then be able to import it in Python 2.7.

    This method is also usable for getting importlib for Python 2.7 off of github. You will only need to change the commit code, link to the github repo, and filename for the python library.

    You can also check if importlib is in your Python 2.7 libraries by looking for the file folder 'importlib' or a similarly-named one in the folder named in step 5.

    I hope this works for you!