Hassan Syed
Hassan Syed

Reputation: 20485

importing a development version of a package from a specific directory

I'm trying to load a development version of a popular Library into my project. Obviously they will have the same package name and therefore cannot co-exist without disambiguation.

My understanding of python module management doesn't go beyond site-packages, the module search path and standard import statements.

My code begins with the following imports:

from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
from IPython.frontend.qt.embedded_kernelmanager import QtEmbeddedKernelManager
from IPython.frontend.qt.kernelmanager import QtKernelManager
from IPython.lib import guisupport

How do I get the IPython symbol to point to a user supplied directory ?

Upvotes: 0

Views: 111

Answers (1)

Amber
Amber

Reputation: 526623

Add that directory to the beginning of the PYTHONPATH. You can do this either by setting the PYTHONPATH environment variable, or by doing something like the following before the imports:

import sys
sys.path.insert(0, "/path/to/dev/IPython/dir")

Another option is to use the virtualenv package to create an environment that gives you sandboxed control over what Python packages are installed.

$ pip install virtualenv
$ virtualenv venv
$ source venv/bin/activate
(venv)$ pip install path/to/IPython/dev/package
(venv)$ python some_script.py

Upvotes: 2

Related Questions