我已经在最新的 Python 2.7 上使用最新的稳定版本的 virtualenv 创建的 virtualenv 中安装了最新的稳定版本的 IPython,但我仍然收到警告说我应该在 virtualenv 中安装 IPython。
如果有任何疑问,我创建了一个 virtualenv 并使用source [virtenv]/bin/activate
激活它,然后使用pip install ipython
安装 ipython。 为了确保我运行的是正确的 ipython,我做which ipython
它正确地指向了虚拟环境中的ipython
二进制文件。 然而,当我调用ipython
时,我得到了WARNING message
:
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv
。
为什么我会收到警告?
尝试从 IPython 内部打印这些:
import os, sys, IPython
print os.environ['VIRTUAL_ENV']
print sys.executable
print IPython.__file__
print sys.path
谢谢@minrk。 以下是输出:
在我从命令行调用 IPython 之前,我的提示正确显示为:
([name of virtual env]) [my regular prompt]
然后,一旦我在 IPython 中:
print os.environ['VIRTUAL_ENV']
# correctly prints the path to the environment
print sys.executable
# Prints the external path to Python (?)
print IPython.__file__
# Prints the external path to the ipython installation's __init__.pyc (?)
print sys.path
# Prints the path to the site-packages folder from the virtualenv at the top.
# Then the bin path of the Python's external installation (?)
# Then some paths to individual packages from the external installation (?)
# Then the paths to individual packages from the virtualenv (and it misses the virtualenv's installation of IPython, ?)
# Then a few more paths to individual packages of the external installation (?)
# Finally the IPython from the external installation (?)
如果我退出 IPython 会话,我的提示正确显示为:
([name of virtual env]) [my regular prompt]
澄清一下,当我说外部安装_ 时,我的意思是在 virtualenv 中安装_not *,也不是系统安装的一部分,而是我在$PATH
和$LD_LIBRARY_PATH
顶部包含的安装
也许我缺少一个环境变量,这让 IPython 感到困惑,以至于我相信我正在使用系统安装而不是我想与 virtualenv 结合使用的外部安装,并且我在PATH
的开头包含了它LD_LIBRARY_PATH
?
你得到了什么head $(which ipython)
?
还有一个: sys.argv
如果 sys.executable 是错误的,那么在加载任何 Python 包之前事情就会出错。 这正是如果系统ipython
不是安装到 env 中的系统会发生的情况(例如,如果您在 env 处于活动状态的情况下执行了/usr/bin/ipython
,我们都应该预料到这种行为会表现不佳)。
修复可能就像hash -r
一样简单,你可以试试吗?
谢谢@minrk。 head $(which ipython)
返回:
#!/path_to_my_virtual_env/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'ipython==0.13.1','console_scripts','ipython'
__requires__ = 'ipython==0.13.1'
import sys
from pkg_resources import load_entry_point
sys.exit(
load_entry_point('ipython==0.13.1', 'console_scripts', 'ipython')()
)
print sys.argv
返回外部 Python 安装的路径。
从终端运行hash -r
似乎有效!
我现在收到不同的警告WARNING: IPython History requires SQLite, your history will not be saved
这很有趣,因为如果我停用我的 virtualenv 并从外部安装运行 ipython,我不会收到此消息。
我假设这就是你所做的:
ipython
并看到了这个警告以下是相关信息,以及hash -r
修复它的原因:
which
不知道这个缓存,所以which ipython
不一定指向ipython
,如果它之前在 shell 会话中被调用过的话。hash -r
只是重置此缓存,以便which
将再次准确。至于 sqlite,你用什么 Python 来做 virtualenv?
@minrk是的,没错! 谢谢。 我正在使用 Python 2.7 x64
你自己构建了 Python 吗? 如果是这样,您需要确保在编译 Python 时 libsqlite 存在且可用。
谢谢@minrk。 libsqlite
似乎对外部IPython可用,即我没有激活虚拟环境时运行的那个(虽然这不是系统安装的那个,因为我已经修改PATH
和LD_LIBRARY_PATH
以在顶部包含外部安装)。 也就是说,我猜外部 IPython 可能正在使用系统安装中的libsqlite
(可能来自LD_LIBRARY_PATH
中的其他路径)。 那可能吗?
无论哪种方式,再次感谢您的所有帮助。 我报告的原始问题已解决,因此我们可以安全地关闭工单。
这通常是编译时问题 - 我认为您需要标头等(如果不重新编译 Python,您将无法修复它)
我将 .py 配置文件执行软件设置为 Notebook,所以它从未运行过!
然后,我找到了!
谢谢!
最有用的评论
修复可能就像
hash -r
一样简单,你可以试试吗?