在virtualenv中运行bpython

在virtualenv中运行bpython,python,pip,virtualenv,bpython,Python,Pip,Virtualenv,Bpython,我已经创建了一个virtualenv并在其中安装了: import在python中工作: $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> i

我已经创建了一个virtualenv并在其中安装了:

import
在python中工作:

$ python
Python 2.7.5 (default, Mar  9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlalchemy
>>> print sqlalchemy.__version__
0.9.7
但它不适用于:

导入sqlalchemy 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 ImportError:没有名为sqlalchemy的模块
为什么bpython找不到安装在virtualenv中的包,即使它是在调用
源炼金术/bin/activate
后执行的?

bpython
必须安装在virtualenv中,否则外部的、系统范围的bpython被调用:

$ source alchemy/bin/activate
(alchemy)[ 10:34PM ]  [ adamatan@rubidium:/tmp ]
$ pip install bpython
...
$ alchemy/bin/bpython
--------------
>>> import sqlalchemy
>>> print sqlalchemy.__version__
0.9.7

bpython
在其shebang中安装了python,并对其进行了硬编码

您可以手动编辑它,使其使用当前的python。通过运行例如
$vi$(哪个bpython)
打开脚本

然后将顶行更改为,例如
#/usr/bin/python3
到例如
#/usr/bin/env python3


这将使它能够使用venv的python运行。bpython并不正式支持它,但它在Mac OS X和Ubuntu上对我一直都有效。

bpython必须在每个virtualenv中安装pip3

$ virtualenv . 
$ source bin/activate 
$ pip3 install bpython
$ pip3 install sqlalchemy
$ bpython


>>导入slqalchemy

在模块为我工作时运行bpython

  • mkdir训练和cd训练
  • venvshell--python=3.8
  • 安装您的依赖项,例如,
    pipenv安装gcloud
  • pipenv安装bpython
  • python-mbpython
  • python-mbpython
    在Python 3.8.5/home/dennys/.local/share/virtualenvs/qTtsVfjR/bin/Python之上的bpython版本0.21
    >>>从gcloud导入bigquery
    >>> 
    
    是否有办法避免这种行为,并使用virtualenv访问/usr/lib bpython?是的。您需要为激活脚本分配资源:$source alchemy/bin/activate$which bpython/usr/bin/bpython$source alchemy/bin/activate$which bpython alchemy/bin/bpython
    $ source alchemy/bin/activate
    (alchemy)[ 10:34PM ]  [ adamatan@rubidium:/tmp ]
    $ pip install bpython
    ...
    $ alchemy/bin/bpython
    --------------
    >>> import sqlalchemy
    >>> print sqlalchemy.__version__
    0.9.7
    
    $ virtualenv . 
    $ source bin/activate 
    $ pip3 install bpython
    $ pip3 install sqlalchemy
    $ bpython