[英]Modify setup.py to support pip install from github
I'd like to modify the setup.py script from the Ansible project so that I can install ansible into a virtualenv like so: 我想修改Ansible项目中的setup.py脚本,以便我可以将ansible安装到virtualenv中,如下所示:
pip install -e git://github.com/lorin/ansible.git#egg=ansible
When I do this now, ansible doesn't run properly, because it can't import the ansible module. 当我现在这样做时,ansible无法正常运行,因为它无法导入ansible模块。
$ ansible
Traceback (most recent call last):
File "/Users/lorin/.virtualenvs/ansible/bin/ansible", line 7, in <module>
execfile(__file__)
File "/Users/lorin/.virtualenvs/ansible/src/ansible/bin/ansible", line 25, in <module>
from ansible.runner import Runner
ImportError: No module named ansible.runner
From what I can tell, one or both of these files tells Python where to find the Ansible module. 据我所知,这些文件中的一个或两个告诉Python在哪里可以找到Ansible模块。
$venv/lib/python2.7/sites-packages/ansible.egg-link
: $venv/lib/python2.7/sites-packages/ansible.egg-link
:
/Users/lorin/.virtualenvs/ansible/src/ansible
.
$venv/lib/python2.7/sites-packages/easy-install.pth
: $venv/lib/python2.7/sites-packages/easy-install.pth
:
import sys; sys.__plen = len(sys.path)
./setuptools-0.6c11-py2.7.egg
./pip-1.0.2-py2.7.egg
/Users/lorin/.virtualenvs/ansible/src/ansible
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)
In both cases, it points to /Users/lorin/.virtualenvs/ansible/src/ansible
, but I think it should actually point to /Users/lorin/.virtualenvs/ansible/src/ansible/lib
, since the ansible module is a subset of that directory. 在这两种情况下,它指向
/Users/lorin/.virtualenvs/ansible/src/ansible
,但我认为它实际上应该指向/Users/lorin/.virtualenvs/ansible/src/ansible/lib
,因为/Users/lorin/.virtualenvs/ansible/src/ansible/lib
模块是该目录的子集。
(Note: I can't just move the ansible/lib/ansible directory to ansible/ansible since the upstream project is unlikely to accept that change). (注意:我不能将ansible / lib / ansible目录移动到ansible / ansible,因为上游项目不太可能接受该更改)。
I tried to modify these files by hand to see if that would resolve the issue, but that revealed a new problem: 我试图手动修改这些文件,看看是否可以解决问题,但这揭示了一个新问题:
$ ansible
Traceback (most recent call last):
File "/Users/lorin/.virtualenvs/ansible/bin/ansible", line 4, in <module>
from pkg_resources import require; require('ansible==0.6')
File "build/bdist.linux-i686/egg/pkg_resources.py", line 2603, in <module>
File "build/bdist.linux-i686/egg/pkg_resources.py", line 666, in require
File "build/bdist.linux-i686/egg/pkg_resources.py", line 565, in resolve
pkg_resources.DistributionNotFound: ansible==0.6
And, "pip freeze" does not report that the package was installed at all: 并且,“pip freeze”并未报告该软件包已安装:
$ pip freeze
Jinja2==2.6
PyYAML==3.10
paramiko==1.7.7.2
pycrypto==2.6
wsgiref==0.1.2
Even once I resolve these issues, I need to somehow set the ANSIBLE_LIBRARY
environment variable to point to $venv/src/ansible/library
when the virtualenv is activated. 即使我解决了这些问题,我还需要以某种方式将
ANSIBLE_LIBRARY
环境变量设置为在激活virtualenv时指向$venv/src/ansible/library
。
So, to sum up, what do I need to do to: 总而言之,我需要做些什么:
ANSIBLE_LIBRARY
environment variable? ANSIBLE_LIBRARY
环境变量? I also don't want to change the behavior of the setup.py script for the other use cases. 我也不想为其他用例更改setup.py脚本的行为。 I don't have any experience with any of the various Python build tools, so I'm at a loss.
我对任何各种Python构建工具都没有任何经验,所以我很茫然。
The problem with editable installation ( -e
flag) is that it requires the project to have a struct like: 可编辑安装(
-e
标志)的问题是它要求项目具有如下结构:
├── projectname
│ ├── projectname
│ │ ├── __init__.py
│ │ └── anotherfile.py
│ └── setup.py
Notice that projectname
subdirectory. 请注意
projectname
子目录。 In Ansible
's case, it does not have this structure. 在
Ansible
的案例中,它没有这种结构。 So it does not work using editable install. 因此使用可编辑安装无效。
Just remove that -e
flag and it might work: 只需删除
-e
标志即可,它可能有效:
pip install -e git://github.com/lorin/ansible.git#egg=ansible
See: 看到:
pip install -e
will work. pip install -e
将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.