PIP problems workaround by @yashodhan

I have noticed a lot of posts recently regarding installation/upgrade of apps. Many link to error 1 (permissions).
This post, by @yashodhan has what seems to be a very good solution - hopefully it will help others…

Thank you @yashodhan

BTW: His solution looks like this

Issue

install.py/setup.py and setup does automatically upgrades pip version to latest causing lot of issues installing packages. (at present while writing this pip version 18.0 was available)
pip version which happens to work is 9.0.3 frappe/erpnext v9 till frappe/erpnext v7

pip install --upgrade pip==9.0.3
pip install --upgrade pip

Either you play along with switching pip versions or do following workaround once and everything seems to be working.

Workaround

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

There’s a better way to do this, which is to update to a more forward compatible syntax:

# -*- coding: utf-8 -*-
from setuptools import setup, find_packages
import re, ast


with open('requirements.txt') as f:
	install_requires = f.read().strip().split('\n')

# get version from __version__ variable in your_app/__init__.py
_version_re = re.compile(r'__version__\s+=\s+(.*)')

with open('your_app/__init__.py', 'rb') as f:
	version = str(ast.literal_eval(_version_re.search(f.read().decode('utf-8')).group(1)))

setup(
	name='your_app',
	version=version,
	description='App for doing your thing',
	author='AgriTheory',
	author_email='tyler@agritheory.com',
	packages=find_packages(),
	zip_safe=False,
	include_package_data=True,
	install_requires=install_requires
)

I understand that it is not up to me or anything, but what are the odds of these solutions could be included in the main stream update/patch system so that future changes don’t produce the same/similar issue?

So, when you create a new app with the bench new-app command, this is what the setup.py looks like. I haven’t chased all the internals, but these changes were prompted by changes to PIP and are Python 3 compatible. So if you’re having problems installing an older App on V11 or with Python 3.x, try refactoring with this example. New apps should follow this format automatically.

I threw up my hands about this the first few times I encountered it because the error looks so serious… anytime I see import ast I back away like it’s some kind of Australian snake.

2 Likes