问题
I am running python-2.7 with virtualenv on a unix server to which I do not have root access. I updated the module tornado using pip install tornado --upgrade because installing ipython required tornado >= 3.1.0 but only version 2.4 was installed by default on the server. However, when I try to open ipython, it still complains that I don't have the updated version.
I confirmed that ipython is correctly aliased to the virtualenv, and that the upgrade had indeed produced tornado version 4.0 in the site-packages of the virtualenv.
However if I open python (correctly aliased to the virtualenv) and import tornado, I find that it is importing the earlier version (2.4) and not the newer version from my virtualenv. Importing another package that was only installed on the virtualenv correctly imports it from the site-packages of the virtualenv.
Any idea how I should tell python to use the updated version of tornado by default instead of the earlier version that isn't on the virtualenv?
One really hacky thing that I tried was appending to my virtualenv activate file the following:
PYTHONPATH=path_to_standardVE/lib/python2.7/site-packages/tornado:$PYTHONPATH
If I check $PYTHONPATH upon startup, it indeed contains this path at the front. However, loading the module in python still loads the 2.4 version.
Thanks!
回答1:
You could try using the pkg_resources
from setuptools
:
import pkg_resources
pkg_resources.require("Tornado==4.0.0")
import tornado
回答2:
Could it be that the virtualEnv is inheriting the global site-packages? I'm not sure if I added -no-site-packages when I set up the virtualEnv. Is there an easy way to address this setting now or to test this possibility?
no-global-site-packages.txt is present in the python2.7 directory
and
orig-prefix.txt contains a parent directory outside of the virtualenv of the older version of tornado that is being loaded
来源:https://stackoverflow.com/questions/25170016/virtualenv-not-finding-updated-module