8

Why do setuptools/easy_install .pth files not place nicely with PYTHONPATH, and how do I get them to play nicely, and keep the directories in my PYTHONPATH before those .pth shoves in the sys.path?

My current problem is I've created a package for our project, with the both PyYAML and PyCrypto as requirements.

  install_requires=["PyYAML",
                    "pycrypto >= 2.3"]

As we've been developing, we've installed PyYaml in the standard directory (/usr/lib64/python2.6/site-packages) with pip. We installed an older version of PyCrypto in there, then discovered we needed the newer one, which we installed under /opt/devtools/lib64/python2.6/site-packages. We've had already been setting our PYTHONPATH to read from /opt first, before /usr/lib64. And that all worked fine in development. When we ran, we got PyCrypto 2.3 from /opt, and PyYaml from /usr/lib64/....

But now, when I'm trying installing in a virtualenv, and when I run python setup.py develop, setuptools/distribute ends up adding /usr/lib64/python2.6/site-packages to the easy-install.pth, but not /opt/devtools/lib64/python2.6/site-packages. It's finding the right versions, as seen in the output:

Using /home/s3447/projects/wsrs.git/emp_parsing
Searching for pycrypto==2.3
Best match: pycrypto 2.3
Adding pycrypto 2.3 to easy-install.pth file

Using /opt/wsrs-devtools/stow/pycrypto-2.3/lib64/python2.6/site-packages
Searching for PyYAML==3.10
Best match: PyYAML 3.10
Adding PyYAML 3.10 to easy-install.pth file

But not adding /opt/... to the easy-install.pth. (Only /usr/lib64... and the directory I ran setup.py in is added to the path.)

The end result is, although I setuptools thinks it was successfully, when I run my code, easy-install.pth decides it knows what I want better than I do, inserts itself before my PYTHONPATH, and I end up importing the wrong version of PyCrypto.

Two questions:

  1. Why is setuptools inconsistent about which directories it adds to the .pth file? I would expect either both directories or neither directory to be installed.

  2. Is there any way to get setuptools to not try to override my PYTHONPATH? Why was that even considered a good idea in the first place?

AFoglia
  • 7,414
  • 3
  • 31
  • 48
  • I assume none of this will be a problem in production, where there will be neither PYTHONPATH nor virtualenvs, but it's still annoying. – AFoglia Sep 28 '11 at 22:24
  • And I'm vague on whether we're using setuptools or distribute. We're running RHEL6, and although the rpm is python-setuptools, I'm pretty sure it's actually distribute. – AFoglia Sep 28 '11 at 22:25
  • 2
    When you installed your virtualenv did you use the `--no-site-packages` option and did you activate your virtualenv before running `python setup.py develop`? – user500198 Sep 28 '11 at 22:37
  • No to the first part, and yes to the second. I'll try the first. – AFoglia Sep 29 '11 at 14:05
  • I just tried the `--no-site-packages` and it works, but that doesn't answer question 1. The `/usr/lib...` directory isn't added until after I install my package that uses PyYaml. So setuptools is adding a hard-coded entry to that previously installed package, but not the previously installed package in a directory in my PYTHONPATH. I would expect it to be either both or neither. – AFoglia Sep 29 '11 at 14:19
  • Perhaps this can shed some light on question 1: [http://stackoverflow.com/a/26035458/6084928](http://stackoverflow.com/a/26035458/6084928) – Lex Scarisbrick Jul 23 '16 at 16:56
  • 2
    I know this does not help, but pip is much better than easy_install – les Jul 25 '16 at 09:53
  • @les Pip is not just "much better" than easy_install. http://stackoverflow.com/questions/3220404/why-use-pip-over-easy-install . In fact, easy_install cannot be used well with virtualenv's as the OP implies they wish to. – std''OrgnlDave Sep 06 '16 at 01:00

1 Answers1

0

From what I understand of your question, this may be where to take your concerns about that: https://github.com/pypa/setuptools/issues/397

Sounds like others have had a similar problem. I could be wrong, I just use pip. I never use easy_install if I can help it.

jimh
  • 809
  • 8
  • 22