Installing Python package in bench virtual environment

After installing a package in python, Import statement error. It says no module is exist.
but in pip list is available. How to solve that.

I tried many packages. For all it shows no module found. Please help

Hi,

Please install it from inside of /frappe-bench/ folder with following command:

bench pip install module_name

replace the module_name with desired module name.

Thanks,

Divyesh Mangroliya

2 Likes

Assuming this is in a development environment, please note that there are 2 different Python environments involved:

  1. The host environment where bench is installed. I typically have this in $HOME/code/frappe/venv - whether you use a virtual environment or not and where you put it is up to you.
  2. The bench environment created after you run bench init frappe-bench ... - I typically have this in $HOME/code/frappe/frappe-bench/env - it is this environment where bench installs modules. When you invoke bench --site site_name console, it is this environment that is invoked.

As @mangroliya suggested, using bench pip install or bench setup requirements ensures that modules go in the correct location. A user is not expected to manage frappe-bench/env manually - use bench commands instead. And probably shouldn’t as bench may overwrite modules.

1 Like

I tried this it works for me as well
in frappe-bench: source ./env/bin/activate
then our python package installation pip install pdfminer.six
deactivate

This install the package insided the bench. in past it installs outside bench

1 Like

will you know how to solve this
DevTools failed to load source map: Could not load content for https://app.turiyaforms.in/file_uploader.bundle.HDDWALJV.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

Looks like a asset bundling or linking error.

See if a bench build --app <app_name> fixes it. If not, check if you are including the path correctly.

Your app contains a file called requirements.txt. Put the name of your desired python package into it and save. Then run “bench setup requirements”. This will “pip” the package.

Create a backup of your system before you do so. If the new package causes a dependency conflict this can break your bench.

2 Likes

I recently discovered that in our custom apps there is a pyproject.toml. By adding your dependencies their, and running bench command:
bench setup requirements
you can access those python packages in the backend.