Install requirements with bench problem (ImportError)

Guys,
help me please to fix my problem.

Environment:

  • bench 4.1.0
  • erpnext 7.0.53
  • frappe 7.0.39

I have added new library to requirements.txt

Why bench doesn’t not install my library during setup?

Not help me restart and some other stuff like:
bench restart
and
bench build
and
bench switch-to-master --upgrade
and
bench migrate
bench clear-cache
bench clear-website-cache

Always Import error

@Katerina_Romanchuk,

please check following thread How to install 3rd party libraries or sdks into the application - #2 by makarand_b.

Thanks, Makarand

Nothing helps me. This not resolve my problem:

try bench update --requirement
or
~frappe-bench/env/bin/pip install -r apps/your_app/requirements.txt


As example:

requirements.txt:

colorama


Setup everything on clean environment

bench get-app custom_application https://github.com/safo-bora/custom_application.git
bench --site erpnext.vm install-app custom_application
bench restart


And verify that my lib was installed:

frappe@erpnext:~/frappe-bench$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
import colorama
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named colorama

ERROR :frowning:


I found interesting thing that it works in this way:

frappe@erpnext:~/frappe-bench$ bench shell
frappe@erpnext:~/frappe-bench/sites$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
import colorama
from colorama import init

OK! Works!


But why I see on my site error with import

how to fix this I don’t know:

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 55, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 30, in execute_cmd
method = get_attr(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 114, in get_attr
method = frappe.get_attr(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 859, in get_attr
return getattr(get_module(modulename), methodname)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 643, in get_module
return importlib.import_module(modulename)
File “/usr/lib/python2.7/importlib/init.py”, line 37, in import_module
import(name)
File “/home/frappe/frappe-bench/apps/custom_application/custom_application/rest_api_lib.py”, line 11, in
from colorama import init
ImportError: No module named colorama

@rmehta: may I ask you to help to investigate this issue on your end as well? This is going to be a real blocker on our end soon.

Thanks!

Hi Guys!

I was taking a look at this issue. Looks like frappe’s sandbox is broken for some third party modules. Here is are two example:

  1. Colorama module:
from colorama import init <--- this causes import error

but this works:

colorama = frappe.get_module("colorama")
colorama.init()
  1. with fedex module from: fedex · PyPI

Same issue:

from fedex.services.track_service import FedexTrackRequest <--- error module not found
from fedex.config import FedexConfig <--- error module not found

But this works:

fedex_track_service = frappe.get_module("fedex.services.track_service")
fedex_config = frappe.get_module("fedex.config")
FedexTrackRequest = fedex_track_service.FedexTrackRequest
FedexConfig = fedex_config.FedexConfig

Seems like the sandbox import path is broken to me on certain modules. I found similar reports for django’s sandbox and colorama.

Still not completely sure how to go about debugging this though.

2 Likes

To test the python console:

bench --site yoursite console

Bench python runs in a virtualenv, to use pip:

env/bin/pip install colorama
2 Likes

Traceback (most recent call last):
File “/home/naztech/.local/bin/bench”, line 11, in
load_entry_point(‘bench’, ‘console_scripts’, ‘bench’)()
File “/home/naztech/bench/bench/cli.py”, line 40, in cli
bench_command()
File “/home/naztech/.local/lib/python2.7/site-packages/click/core.py”, line 764, in call
return self.main(*args, **kwargs)
File “/home/naztech/.local/lib/python2.7/site-packages/click/core.py”, line 717, in main
rv = self.invoke(ctx)
File “/home/naztech/.local/lib/python2.7/site-packages/click/core.py”, line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/home/naztech/.local/lib/python2.7/site-packages/click/core.py”, line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/home/naztech/.local/lib/python2.7/site-packages/click/core.py”, line 555, in invoke
return callback(*args, **kwargs)
File “/home/naztech/bench/bench/commands/update.py”, line 138, in switch_to_branch
switch_to_branch(branch=branch, apps=list(apps), upgrade=upgrade)
File “/home/naztech/bench/bench/app.py”, line 397, in switch_to_branch
switch_branch(branch, apps=apps, bench_path=bench_path, upgrade=upgrade)
File “/home/naztech/bench/bench/app.py”, line 383, in switch_branch
update_requirements()
File “/home/naztech/bench/bench/utils.py”, line 443, in update_requirements
install_app(app, bench_path=bench_path)
File “/home/naztech/bench/bench/app.py”, line 172, in install_app
find_links=find_links))
File “/home/naztech/bench/bench/utils.py”, line 161, in exec_cmd
raise CommandFailedError(cmd)
bench.utils.CommandFailedError: ./env/bin/pip install -q -e ./apps/erpnext