V12 bench on system having v14 - ashish-greycube/help GitHub Wiki
To create v12 bench on system which has already v14 bench, do following steps:
[1] Required Packages are already installed in system. So no need to do it again.
like: git,MySQL server,Redis Server, libfontconfig wkhtmltopdf, curl, yarn.
[2] Python version 3.8 is required. If not, then run:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt install python3.8 python3.8-dev
sudo apt install python3.8-venv
sudo apt install virtualenv
virtualenv --python python3.8 env
[3] v14 bench uses latest version of node 18. So for v12 bench, node v14 is required.
[4] nvm is already installed in system. Can check nvm is there or not and which node version is by default running by below command:
```
nvm ls
[5] Now just install node v14 by following command:
[6] Run below command to check which node version is set as default:
nvm list
[7] If default version is other than 14,then to set node v14 as default, run:
nvm alias default 14.21.3
[8] Run below command to initialize frappe bench v12:
bench init /home/greycube/v12-bench --frappe-path https://github.com/frappe/frappe --frappe-branch version-12 --python /usr/bin/python3.8
[9] Create site:
bench new-site test12 --force
[10] Now open vs code replace xlsxutils.py by below code to remove numpy error. Go to frappe-bench/apps/frappe/xlsxutils.py:
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
# import openpyxl
import xlrd
import re
# from openpyxl.styles import Font
# from openpyxl import load_workbook
# from openpyxl.utils import get_column_letter
from six import BytesIO, string_types
ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]')
# return xlsx file object
def make_xlsx(data, sheet_name, wb=None, column_widths=None):
return
column_widths = column_widths or []
if wb is None:
wb = openpyxl.Workbook(write_only=True)
ws = wb.create_sheet(sheet_name, 0)
for i, column_width in enumerate(column_widths):
if column_width:
ws.column_dimensions[get_column_letter(i + 1)].width = column_width
row1 = ws.row_dimensions[1]
row1.font = Font(name='Calibri', bold=True)
for row in data:
clean_row = []
for item in row:
if isinstance(item, string_types) and (sheet_name not in ['Data Import Template', 'Data Export']):
value = handle_html(item)
else:
value = item
if isinstance(item, string_types) and next(ILLEGAL_CHARACTERS_RE.finditer(value), None):
# Remove illegal characters from the string
value = re.sub(ILLEGAL_CHARACTERS_RE, '', value)
clean_row.append(value)
ws.append(clean_row)
xlsx_file = BytesIO()
wb.save(xlsx_file)
return xlsx_file
def handle_html(data):
# return if no html tags found
data = frappe.as_unicode(data)
if '<' not in data:
return data
if '>' not in data:
return data
from html2text import HTML2Text
h = HTML2Text()
h.unicode_snob = True
h = h.unescape(data or "")
obj = HTML2Text()
obj.ignore_links = True
obj.body_width = 0
try:
value = obj.handle(h)
except Exception:
# unable to parse html, send it raw
return data
value = ", ".join(value.split(' \n'))
value = " ".join(value.split('\n'))
value = ", ".join(value.split('# '))
return value
def read_xlsx_file_from_attached_file(file_url=None, fcontent=None, filepath=None):
return
if file_url:
_file = frappe.get_doc("File", {"file_url": file_url})
filename = _file.get_full_path()
elif fcontent:
from io import BytesIO
filename = BytesIO(fcontent)
elif filepath:
filename = filepath
else:
return
rows = []
wb1 = load_workbook(filename=filename, read_only=True, data_only=True)
ws1 = wb1.active
for row in ws1.iter_rows():
tmp_list = []
for cell in row:
tmp_list.append(cell.value)
rows.append(tmp_list)
return rows
def read_xls_file_from_attached_file(content):
book = xlrd.open_workbook(file_contents=content)
sheets = book.sheets()
sheet = sheets[0]
rows = []
for i in range(sheet.nrows):
rows.append(sheet.row_values(i))
return rows
def build_xlsx_response(data, filename):
xlsx_file = make_xlsx(data, filename)
# write out response as a xlsx type
frappe.response['filename'] = filename + '.xlsx'
frappe.response['filecontent'] = xlsx_file.getvalue()
frappe.response['type'] = 'binary'
[11] Install erpnext app on site:
bench --site test12 install-app erpnext
[12] Everytime when you try to install any app, first change xlxsutils.py by above code,then install app and then revert file to original content. [13] To change xlsxutils.py to its original content,In terminal,Go to frappe-bench->apps->frappe, do following:
$ git checkout .
[14] Do bench start.
Notes:
[1] All these commands run from frappe user.
[2] It will remain with node-saas error. Only numpy error will be solved.
[3] If desk looks proper then no need to solve node-saas error otherwise try with different node versions which suitable for node v14.
[4] To install node-saas version through npm, run below command. This command should run from frappe-bench->apps->frappe
npm install [email protected]
[5] Different versions of node-saas can checkout at,
[Node-saas versions](https://github.com/sass/node-sass)
Final Installation steps for version-12 bench
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt install python3.7 python3.7-dev
sudo apt install python3.7-venv
sudo apt install virtualenv
virtualenv --python python3.7 env
nvm install 12.18.1
nvm use 12.18.1
bench init v12-bench --frappe-branch version-12 --python python3.7
source env/bin/activate
pip install numpy==1.21.6
deactivate
bench get-app erpnext --branch version-12
bench new-site demo12 --install-app erpnext