Fully Automated Install Script for ERPNext Version 14

Hi flex2sky

Sorry not to reply earlier - have been snowed under. That fail2ban problem is NEW.

I always install on a fresh copy of Ubuntu Server. The repos for 23.10 install python 3.11 & for 24.04 that’s 3.12. Starting in 3.11 there’s now a requirement to use a venv when installing stuff - otherwise “sudo pip3 install frappe-bench” should give “error: externally-managed-environment”

See: python - pip install -r requirements.txt is failing: "This environment is externally managed" - Stack Overflow
and: PEP 668 – Marking Python base environments as “externally managed” | peps.python.org

/usr/lib/python3.12/EXTERNALLY-MANAGED is just an empty marker file and removing it causes Python to revert to the way it behaves in 3.10. I included this after reading installs like: Installing ERPNext version 15 on Ubuntu 23+

That said - I now see it’s a very ham-fisted way for production. Years down the track you may end up with multiple incompatible versions of Python all over your drive. I’m not experienced with venv - so I’ll try a deep dive into pipx & learn how to use that.

With regards fail2ban - I just did an install (24.04) - after “$ bench setup role fail2ban” you get:

ERROR! [DEPRECATED]: ansible.builtin.include has been removed. Use include_tasks or import_tasks instead. This feature was removed from ansible-core in a release after 2023-05-16. Please update your playbooks.

The error appears to be in ‘/usr/local/lib/python3.12/dist-packages/bench/playbooks/roles/mariadb/tasks/main.yml’: line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


  • include: centos.yml
    ^ here
    ERROR: Command ‘[‘ansible-playbook’, ‘-c’, ‘local’, ‘site.yml’, ‘-vvvv’, ‘-e’, ‘{“production”: true, “admin_emails”: “”, “mysql_root_password”: null, “container”: false}’, ‘-t’, ‘fail2ban’]’ returned non-zero exit status 1.

From Ansible’s site: ansible.builtin.include – Include a play or task list — Ansible Documentation … “we are looking at deprecating it in the near future.” That was 2.10 & they appear coy in updating their docs. But see: ansible.builtin.include has been Removed in Ansible version 2.16 · Issue #389 · ansible-ThoTeam/nexus3-oss · GitHub

And with the install I just did I’ve got:
bower@erpdemo:~/frappe-bench$ ansible --version
ansible [core 2.16.7]

I’ll can check install logs at work tomorrow. I didn’t get an error last time I installed on 24.04. I’ll also try to flesh out that node vs nodejs issue.

I did an install on what must have been the beta version on 20 March - no problem. That was with ansible-9.3.0, ansible-core-2.16.4 & fail2ban (1.0.2-3).

Then on 14 May I did another install on 24.04 - again no prob. With ansible-9.5.1, ansible-core-2.16.6 & fail2ban (1.0.2-3).

So - whatever’s gone wrong must be quite recent.

The install I did last night that reproduced your error was with ansible-playbook [core 2.16.7]. Version 2.16.7 was released on 20 May - if that fits with the error you got. Couldn’t see anything in the changelog relating to this though: ansible/changelogs/CHANGELOG-v2.16.rst at v2.16.7 · ansible/ansible · GitHub

You’ll see that if you do a “sudo bench setup production [username]” on the failed install you should get the error again.

I’ll post this to the main ERPNext forum & see what they say.

@Elkanaaa I have a fix for it already in the install script. i am including support for 23.04, 24.04 and Debian 12. Will be published in a couple of hours. I’m just testing across distros and versions to ensure full support is still guaranteed for existing distros.

UPDATE: Support added for Ubuntu 23.04, 24.04 and Debian 12. Also, ERPNext installation is now optional and added optional install for HRMS.

1 Like

Just tried - everything ran fine until HRMS install.

Installation for Frappe HR app failed due to an error. Please try re-installing the app or report the issue on https://github.com/frappe/hrm
s/issues/new if not resolved.
An error occurred while installing hrms: Module import failed for Expense Claim Type, the DocType you’re trying to open might be deleted.<br
Error: No module named ‘frappe.core.doctype.expense_claim_type’

Then the script stopped - and the webpage gives:

Uncaught Server Exception

There was an error building this page

Error Code: 404

If you don’t know what just happened, and wish to file a ticket please
copy the error below and share it.

I’ll try it again in a few hours without the HRMS module.

Tried again without HRMS. Ran smoothly and installed no problem.

Ahh - just noticed - instead of a directory “frappe-bench” - it created one named “v14-bench” instead (and I installed ERPNext v15).

My bad. I have reverted the bench directory to the default frappe-bench.

i noticed that HRMS install fails sometimes but its got nothing to do with the script.

1 Like

So it is better to skip HRMS in auto installer and do it manually right?

Yes. Although the failure doesn’t occur every time

Hello @flexy2ky,

it is me again :), i want to install ERPNext by your script, but i get error;

Enter the site name (If you wish to install SSL later, please enter a FQDN): erpnextdemo.local
Enter the Administrator password:
Confirm password:
Password confirmed

Now setting up your site. This might take a few minutes. Please wait...
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 114, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 20, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 68, in new_site
    _new_site(
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 87, in _new_site
    install_db(
  File "/home/frappe/frappe-bench/apps/frappe/frappe/installer.py", line 160, in install_db
    setup_database(force, source_sql, verbose, no_mariadb_socket)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/__init__.py", line 21, in setup_database
    return frappe.database.mariadb.setup_db.setup_database(
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/setup_db.py", line 31, in setup_database
    if force or (db_name not in dbman.get_database_list()):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/db_manager.py", line 50, in get_database_list
    return self.db.sql("SHOW DATABASES", pluck=True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 211, in sql
    self.connect()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 117, in connect
    self._conn: "MariadbConnection" | "PostgresConnection" = self.get_connection()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 107, in get_connection
    conn = self._get_connection()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 113, in _get_connection
    return self.create_connection()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/mariadb/database.py", line 116, in create_connection
    return pymysql.connect(**self.get_connection_settings())
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 361, in __init__
    self.connect()
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 669, in connect
    self._request_authentication()
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 957, in _request_authentication
    auth_packet = self._read_packet()
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/connections.py", line 775, in _read_packet
    packet.raise_for_error()
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/protocol.py", line 219, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/pymysql/err.py", line 150, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1698, "Access denied for user 'root'@'localhost'")
An error occurred on line 369 with exit status 0

root had password but i removed it (How to remove root password on Debian? - Unix & Linux Stack Exchange), still gives errors.

1 Like

Hi flex2sky

That Python marker file - /usr/lib/python3.11/EXTERNALLY-MANAGED - or - /usr/lib/python3.12/EXTERNALLY-MANAGED can magically reappear.

Just tried to update Bench in an old production install I did on 23.10 - sudo pip3 install --upgrade frappe-bench - and was surprised to get a “This environment is externally managed”.

Sure enough - in /usr/lib/python3.11 - that EXTERNALLY-MANAGED file is back. Must have been some update (currently Python 3.11.6).

I’ll try this weekend to get your script to run with pipx (instead of removing that file) and let you know how I go.

1 Like

Install worked without a hitch - Ubuntu 24 on AWS EC2. Thanks so much for this script it is very cool :sunglasses:

1 Like

To disable the externally-managed-environment error

sudo python3 -m pip config --global set global.break-system-packages true
2 Likes

Thanks NURAV - that works well. I included it in a copy of this install script - after deleting the bit about “# Check if EXTERNALLY-MANAGED file exists and remove it”.
So the copy I used now looks:

334  # Install bench
335  echo -e "${YELLOW}Now let's install bench${NC}"
336  sleep 2
337
338  sudo python3 -m pip config --global set global.break-system-packages true
339
340  sudo apt install python3-pip -y
341  sudo pip3 install frappe-bench
342
343  # Initiate bench in frappe-bench folder, but get a supervisor can't restart bench error...

Installed to production no problem.

1 Like

@Elkanaaa You could make a pull request so others can benefit from this update if you’ve tested it and it’s working.

1 Like

Hi, does anyone know why I keep getting the following error “An error occurred on line 351 with exit status 0” this happens right after0
yarn run v1.22.22
$ node esbuild --production --run-build-command
Browserslist: caniuse-lite is outdated. Please run:
npx update-browserslist-db@latest
Why you should do it regularly: GitHub - browserslist/update-db: CLI tool to update caniuse-lite to refresh target browsers from Browserslist config

Hi im trying to use the script but have an error, when i restart the VPS, and start again now say

Site erpnext.testsite.com already exists
An error occurred on line 369 with exit status 0

What i need to do to use the same site i put in the first time

Already fixed with this
bench drop-site --no-backup