ImportError: No module named req | bench init unable to install version frappe 7.x.x

I am running bench version 4.1.0 - installed with frappe user & production mode on Ubuntu 14.04 LTS

$ pip -V
pip 9.0.3 from /usr/local/lib/python2.7/dist-packages/pip-9.0.3-py2.7.egg (python 2.7)

$ bench init frappe-bench-v7 --frappe-branch v7.x.x --verbose
/usr/local/lib/python2.7/dist-packages/cryptography/hazmat/primitives/constant_time.py:26: CryptographyDeprecationWarning: Support for your Python version is deprecated. The next version of cryptography will remove support. Please upgrade to a 2.7.x release that supports hmac.compare_digest as soon as possible.
  utils.DeprecatedIn23,
INFO:bench.utils:virtualenv -q env -p /usr/bin/python
Already using interpreter /usr/bin/python
INFO:bench.utils:env/bin/pip -q install wheel
INFO:bench.utils:env/bin/pip -q install six
INFO:bench.utils:env/bin/pip -q install -e git+https://github.com/frappe/python-pdfkit.git#egg=pdfkit
INFO:bench.app:getting app frappe
INFO:bench.utils:git clone https://github.com/frappe/frappe.git --branch v7.x.x  --origin upstream
Cloning into 'frappe'...
remote: Counting objects: 152473, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 152473 (delta 0), reused 1 (delta 0), pack-reused 152470
Receiving objects: 100% (152473/152473), 167.75 MiB | 11.88 MiB/s, done.
Resolving deltas: 100% (115576/115576), done.
Checking connectivity... done.
('installing', u'frappe')
INFO:bench.app:installing frappe
INFO:bench.utils:frappe-bench-v7/env/bin/pip install   -e frappe-bench-v7/apps/frappe --no-cache-dir
Obtaining file:///home/frappe/frappe-bench-v7/apps/frappe
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/frappe/frappe-bench-v7/apps/frappe/setup.py", line 2, in <module>
        from pip.req import parse_requirements
    ImportError: No module named req
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /home/frappe/frappe-bench-v7/apps/frappe/
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 11, in <module>
    load_entry_point('bench', 'console_scripts', 'bench')()
  File "/home/frappe/.bench/bench/cli.py", line 40, in cli
    bench_command()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/.bench/bench/commands/make.py", line 30, in init
    python               = python)
  File "/home/frappe/.bench/bench/utils.py", line 75, in init
    get_app(frappe_path, branch=frappe_branch, bench_path=path, build_asset_files=False, verbose=verbose)
  File "/home/frappe/.bench/bench/app.py", line 135, in get_app
    install_app(app=app_name, bench_path=bench_path, verbose=verbose)
  File "/home/frappe/.bench/bench/app.py", line 179, in install_app
    find_links=find_links))
  File "/home/frappe/.bench/bench/utils.py", line 159, in exec_cmd
    raise CommandFailedError(cmd)
bench.utils.CommandFailedError: frappe-bench-v7/env/bin/pip install   -e frappe-bench-v7/apps/frappe --no-cache-dir

Issue

bench’s install.py / setup.py from apps does automatically upgrades pip package itself causing lot of issues dependencies installation as well as ERPNext.
I found out that degrading version to 9.0.3 works with older Frappe-ERPNext versions well (anything below v9) but for latest versions v10 and upcoming v11 you need lates pip version 10/18 to load all required packages and internal python libraries.

  • For Frappe/ERPNext from version 7 to 9 : pip version 9.0.3 happens to work smooth setup
  • For Frappe/ERPNext from version 10 & 11 : pip version 18 happens to work smooth setup

How to check pip version?

System wide (if available) check with root user:

pip -V
# OR
pip --version
# CLI Output:
pip 18.0 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

How to check Bench virtual environment pip version?

su - frappe3 -s /bin/bash #switching to specific frappe user from root
cd ~/frappe-bench
~/frappe-bench/env/bin/pip --version
# OR
~/frappe-bench/env/bin/pip --V
# CLI Output:
pip 9.0.3 from /home/frappe3/frappe-bench/env/local/lib/python2.7/site-packages (python 2.7)

Note: in my case frappe3 is system user and frappe-bench is where my version 7.x.x Frappe and ERPNext apps are installed to be used for sites to serve it.

Workaround

pip install --upgrade pip==9.0.3
pip install --upgrade pip #This upgrades to latest version

for processing installation without failing for dependencies and required pip packages.
open setup.py file in any preferred editor locate following

from pip.req import parse_requirements

replace with

try: # for pip >= 10
    from pip._internal.req import parse_requirements
except ImportError: # for pip <= 9.0.3
    from pip.req import parse_requirements

For me it took few hours to figure out what really went wrong as I was dealing with customized frappe and developed modules of a client I am suppose to migrate to new environment.
Either way, you play along with switching pip versions and code workaround till all errors goes away…

4 Likes

Hi all,

this problem still exists in the development VM.
Could it be fixed and a new VM be generated? It took me quite some time to find this thread and probably others will have the same problem!

The above helped:

try: # for pip >= 10
    from pip._internal.req import parse_requirements
except ImportError: # for pip <= 9.0.3
    from pip.req import parse_requirements

@yashodhan many thanks your fix notes worked here for me on a v8 to v11 update -

INFO:bench.app:installing library_management
INFO:bench.utils:./env/bin/pip install -q  -e ./apps/library_management 
/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/cryptography/hazmat/primitives/constant_time.py:26: CryptographyDeprecationWarning: Support for your Python version is deprecated. The next version of cryptography will remove support. Please upgrade to a 2.7.x release that supports hmac.compare_digest as soon as possible.
  utils.DeprecatedIn23,
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/frappe/frappe-bench/apps/library_management/setup.py", line 3, in <module>
        from pip.req import parse_requirements
    ImportError: No module named req
    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /home/frappe/frappe-bench/apps/library_management/
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 11, in <module>
    load_entry_point('bench', 'console_scripts', 'bench')()
  File "/home/frappe/bench-repo/bench/cli.py", line 40, in cli
    bench_command()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/bench-repo/bench/commands/update.py", line 60, in update
    _update(pull, patch, build, bench, auto, restart_supervisor, restart_systemd, requirements, no_backup, force=force, reset=reset)
  File "/home/frappe/bench-repo/bench/commands/update.py", line 83, in _update
    update_requirements(bench_path=bench_path)
  File "/home/frappe/bench-repo/bench/utils.py", line 438, in update_requirements
    install_app(app, bench_path=bench_path)
  File "/home/frappe/bench-repo/bench/app.py", line 171, in install_app
    find_links=find_links))
  File "/home/frappe/bench-repo/bench/utils.py", line 159, in exec_cmd
    raise CommandFailedError(cmd)
bench.utils.CommandFailedError: ./env/bin/pip install -q  -e ./apps/library_management

It seems you have library_management app which is failing due to pip version issues I have shared in earlier posts.

if you simply remove app, error might go away.

bench uninstall-app library_management

# use following, if upgrade fails again to take out library_management completely from bench
bench remove-app library_management

Thanks yashodhan -

Yes that’s certainly an option particularly since library_management is the basic tutorial exercise…

1 Like