Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running bpython inside a virtualenv

I have created a virtualenv and installed SQLAlchemy in it:

$ virtualenv alchemy
$ source alchemy/bin/activate
$ pip install sqlalchemy

import works in 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

But it does not work in bpython:

>>> import sqlalchemy
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ImportError: No module named sqlalchemy

Why can't bpython find the package installed in the virtualenv, even though it is executed after source alchemy/bin/activate is called?

like image 746
Adam Matan Avatar asked Aug 21 '14 19:08

Adam Matan


People also ask

How do I run a Python script in virtual environment Windows?

In "Program/script" textbox you set the path to Python executable (in my case is inside the virtualenv folder). "Add arguments" => Just the name of your Python script (name. ppy). "Start in" => The full path of your Python script (without the name.py).

Can we install Python in virtual environment?

virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip.

Is VENV and virtualenv the same?

These are almost completely interchangeable, the difference being that virtualenv supports older python versions and has a few more minor unique features, while venv is in the standard library.


1 Answers

bpython must be installed in the virtualenv, otherwise the external, system-wide bpython is called:

$ source alchemy/bin/activate
(alchemy)[ 10:34PM ]  [ adamatan@rubidium:/tmp ]
$ pip install bpython
...
$ alchemy/bin/bpython
--------------
>>> import sqlalchemy
>>> print sqlalchemy.__version__
0.9.7
like image 161
Adam Matan Avatar answered Oct 03 '22 05:10

Adam Matan