{"action":"opened","issue":{"url":"https://api.github.com/repos/mbj4668/pyang/issues/225","repository_url":"https://api.github.com/repos/mbj4668/pyang","labels_url":"https://api.github.com/repos/mbj4668/pyang/issues/225/labels{/name}","comments_url":"https://api.github.com/repos/mbj4668/pyang/issues/225/comments","events_url":"https://api.github.com/repos/mbj4668/pyang/issues/225/events","html_url":"https://github.com/mbj4668/pyang/issues/225","id":153577504,"number":225,"title":"`share/yang/modules` not under `sys.preffix` when installing from pip","user":{"login":"abravalheri","id":320755,"avatar_url":"https://avatars.githubusercontent.com/u/320755?v=3","gravatar_id":"","url":"https://api.github.com/users/abravalheri","html_url":"https://github.com/abravalheri","followers_url":"https://api.github.com/users/abravalheri/followers","following_url":"https://api.github.com/users/abravalheri/following{/other_user}","gists_url":"https://api.github.com/users/abravalheri/gists{/gist_id}","starred_url":"https://api.github.com/users/abravalheri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abravalheri/subscriptions","organizations_url":"https://api.github.com/users/abravalheri/orgs","repos_url":"https://api.github.com/users/abravalheri/repos","events_url":"https://api.github.com/users/abravalheri/events{/privacy}","received_events_url":"https://api.github.com/users/abravalheri/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-07T06:32:37Z","updated_at":"2016-05-07T06:32:37Z","closed_at":null,"body":"On Debian 8.2 (jessie), pip (from `python-pip` package) places the files from `modules` folder under `/usr/local/share/yang/modules`.\r\n\r\nSince pyang rely on `sys.prefix` to discover the location for default modules (ietf & iana), it incorrectly assumes the default installation directory as `/usr/share/yang/modules`. Therefore, **it cannot find common modules (implicit `$YANG_MODPATH`),  e.g. `ietf-yang-types`, resulting in errors**.\r\n\r\nThese errors can be replicated with the following procedure.\r\n\r\n- Install the most recent version of pyang using pip (from git repo):\r\n```bash\r\ncd /tmp\r\ngit clone https://github.com/mbj4668/pyang.git\r\ncd pyang\r\npython setup.py bdist_wheel\r\nsudo pip install dist/pyang-1.6-py2.py3-none-any.whl\r\n```\r\n- Create an `example-sport.yang` file (based on [wikipedia example](https://en.wikipedia.org/wiki/YANG#Example))\r\n```yang\r\nmodule example-sports {\r\n  namespace \"http://example.com/example-sports\";\r\n  prefix sports;\r\n\r\n  import ietf-yang-types {\r\n    prefix yang;\r\n  }\r\n\r\n  container sports {\r\n    config true;\r\n    list person {\r\n      key \"name\";\r\n      leaf name {\r\n        type string;\r\n      }\r\n      leaf birthday {\r\n        type yang:date-and-time;\r\n        mandatory true;\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n- Compile the module\r\n```shell\r\npyang -f yin example-sports.yang -o example-sports.yin\r\n# => example-sports.yang:5: error: module \"ietf-yang-types\" not found in search path\r\n```\r\n\r\nThe following information describes the system state\r\n```bash\r\nwhich python\r\n# => /usr/bin/python\r\npython -V\r\n# => Python 2.7.9\r\npython -c 'import sys; print sys.prefix'\r\n# => /usr\r\nwhich pyang\r\n# => /usr/local/bin/pyang\r\nls /usr/share/yang/\r\n# => ls: cannot access /usr/share/yang/: No such file or directory\r\nls /usr/local/share/yang/\r\n# => schema/   modules/   xslt/   images/\r\n```\r\n\r\nNote that, when `import` statement is removed and `yang:date-and-time` is changed to `string`, the module compiles without problem.\r\n\r\nI think this behavior cannot be detected in CI tests, since travis uses `env.sh`, which explicitly defines `$YANG_MODPATH`\r\n\r\n"}}