Skip to content

Instantly share code, notes, and snippets.

@goweiting
Last active January 7, 2021 17:05
Show Gist options
  • Save goweiting/b3a8c67c0f7ad376d3ce73f2c7729224 to your computer and use it in GitHub Desktop.
Save goweiting/b3a8c67c0f7ad376d3ce73f2c7729224 to your computer and use it in GitHub Desktop.
Installing graph-tool with other packages staying in an virtual env (conda)

There is no guarantee that this will work, i wrote this so in case anyone else have the same goal in mind. Using: Ubuntu 16.04; miniconda2

What i want to achieve:

  1. use graph-tool
  2. all other packages should fall in a virtual environment

Failed attempts:

  1. I attempted to build graph-tool from scratch but did not work, and couldnt seem to pull everything together.
  2. Attempt to use all the graph-tool packages on anaconda cloud... (idgi)

The attempt:

  1. .deb from graph-tool is installed: sudo apt-get install python-graph-tool

  2. All the additional apt-get binaries are installed too, and check (see next section)

  3. Create conda environment (if you havent), otherwise, activate the environment: a. conda create -n <env> python=2.7 # quite sure this is extensible to the python3 b. source activate <env>

  4. install the conda packagesconda install numpy scipy matplotlib cairo pycairo This has to be done so that graph-tool does not use the system's packages but rather your numpy/scipy/... packages! also because, this works and if not it doesnt...

  5. link the dist-packages where your graph_tool exists (on the system)

$ cd /path/to/anaminiconda/envs/<env>/lib/python2.7/site-packages
$ touch dist-packages.pth
$ echo "/usr/lib/python2.7/dist-packages/" >> dist-packages.pth
# or you can open your text editor and type the path to your dist-packages into the file `dist-packages.pth`

This would tell conda to look at your dist-packages should you tried to import sth that is not in the site-packages

  1. Check that graph-tool is properly installed!

Check that graph-tool is properly installed on your system:

check that graph-tool is properly installed:

in a terminal:
$ which python
/usr/bin/python # ensure that you are using the system's python
$ python -c "from graph_tool.all import *"
# WARNING messages are okay, as long as it does not throw ImportError, 
# or any of that sort that means that the installation has failed

Check that graph-tool is now installed

# in your conda environment:
<env> $ python -c "from graph_tool.all import *"
If no errors are thrown, then you are good :)
@maksim96
Copy link

maksim96 commented Jan 7, 2021

nice workaround, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment