3

I am using a venv to install a newer version of the elpy package from PyPI than is available on the root environment. Querying from pip, I see the following version for elpy:

~/python/standalone $ pip show elpy
---
Name: elpy
Version: 1.4.2
Location: /home/wdkrnls/python/env/local/lib/python2.7/site-packages
Requires: flake8

However, using the interpreter gives me the root environment version.

In [4]: import elpy
In [5]: elpy.__version__
Out[5]: '1.3.0'
In [6]: ?elpy
Type:       module
String Form:<module 'elpy' from '/home/ipython/Enthought2/lib/python2.7/site-packages/elpy/__init__.pyc'>
File:       /home/ipython/Enthought/lib/python2.7/site-packages/elpy/__init__.py
Docstring:
The Emacs Lisp Python Environment.

Why does this happen and how do I fix it?

My sys.path is messy, and I have no idea how to clean it up (I've upgraded Canopy distributions in the past), but here it is:

['',
 '/home/wdkrnls/python/env/local/bin',
 '/home/wdkrnls/python/env/local/lib/python2.7/site-packages/jediepcserver-0.0.0-py2.7.egg',
 '/home/wdkrnls/python/env/local/lib/python2.7/site-packages/epc-0.0.5-py2.7.egg',
 '/home/wdkrnls/python/env/local/lib/python2.7/site-packages/sexpdata-0.0.3-py2.7.egg',
 '/home/ipython/Enthought2/lib/python2.7/site-packages/PyCifRW-3.3-py2.7-linux-x86_64.egg',
 '/home/ipython/Enthought2/lib/python2.7/site-packages/graphtool-0.5.2-py2.7.egg',
 '/home/ipython/Enthought2/lib/python2.7/site-packages',
 '/home/wdkrnls/python/env/local/lib/python2.7/site-packages/argparse-1.2.1-py2.7.egg',
 '/share/apps/python/Canopy/appdata/canopy-1.3.0.1715.rh5-x86_64/lib/python2.7/site-packages',
 '/home/ipython/Enthought/Canopy_64bit/User/lib/python2.7/site-packages',
 '/home/wdkrnls/python/packages',
 '/home/wdkrnls/python/standalone',
 '/share/apps/python/Canopy/appdata/canopy-1.3.0.1715.rh5-x86_64/lib/python27.zip',
 '/share/apps/python/Canopy/appdata/canopy-1.3.0.1715.rh5-x86_64/lib/python2.7',
 '/share/apps/python/Canopy/appdata/canopy-1.3.0.1715.rh5-x86_64/lib/python2.7/plat-linux2',
 '/share/apps/python/Canopy/appdata/canopy-1.3.0.1715.rh5-x86_64/lib/python2.7/lib-tk',
 '/share/apps/python/Canopy/appdata/canopy-1.3.0.1715.rh5-x86_64/lib/python2.7/lib-old',
 '/share/apps/python/Canopy/appdata/canopy-1.3.0.1715.rh5-x86_64/lib/python2.7/lib-dynload',
 '/home/wdkrnls/python/env/local/lib/python2.7/site-packages',
 '/home/ipython/Enthought2/lib/python2.7/site-packages/PIL',
 '/home/ipython/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/PIL',
 '/share/apps/python/Canopy/appdata/canopy-1.3.0.1715.rh5-x86_64/lib/python2.7/site-packages/IPython/extensions',
 '/home/wdkrnls/python/packages',
 '/home/wdkrnls/python/standalone']

How should I go about maintaining sys.path? Do I need all these .egg files for a Canopy distribution?

wdkrnls
  • 4,548
  • 7
  • 36
  • 64

2 Answers2

0

It looks like you're using ipython. If you haven't installed ipython in the virtualenv, the ipython executable that's being run will be the system one.

To check, compare which ipython with which python. The Python executable should be the one in the virtualenv. If bet that the ipython executable is the system one.

Joe Kington
  • 275,208
  • 71
  • 604
  • 463
  • 1
    '/home/wdknrls/python/env/local/bin/ipython' is the location of my installation of ipython I get with `which`, compared with '/home/wdkrnls/python/env/local/bin/python`. Both seem to be local. – wdkrnls Jul 16 '14 at 20:47
  • @wdkrnls - Well, nevermind then! Did you use the `--no-site-packages` option when you created the virtualenv? – Joe Kington Jul 16 '14 at 21:44
  • I think I told it to inherit from the site packages, because there are site packages I want to use, if I don't have my own preferred versions installed locally. – wdkrnls Jul 17 '14 at 19:09
0

The order of precedence can be found by printing sys.path

Jonathan March
  • 5,800
  • 2
  • 14
  • 16
  • Yes, the precedence is wrong. What's the cleanest way to fix it? – wdkrnls Jul 17 '14 at 01:07
  • What is your sys.path, and what are the values of environment variables PYTHONPATH and PYTHONHOME if any? – Jonathan March Jul 17 '14 at 11:28
  • I've only got two directories in PYTHONPATH: /home/wdkrnls/python/packages:/home/wdkrnls/python/standalone. There is nothing in PYTHONHOME. – wdkrnls Jul 17 '14 at 13:13
  • what is your sys.path? – Jonathan March Jul 17 '14 at 16:27
  • I added `sys.path` to the question. It's really messy, but I'm not sure how to properly maintain it. Any tips? – wdkrnls Jul 17 '14 at 19:08
  • Somehow you have commingled two python installations, a recipe for chaos. What do you get from `which python`, `which ipython`, `which pip`? And exactly what program (from where) are you running when you get the output which you describe as "using the interpreter"? – Jonathan March Jul 18 '14 at 22:35